Problems trying to list csv

Asked

Viewed 31 times

0

Hello,

I am trying to read the csv type files from a folder via script.

via browser it presents me the correct values of the array, but via CLI it presents me an empty array. Follow the code

$files = glob('*.csv');
var_dump($files);

Output via browser:

array(2) { [0]=> string(22) "Perdas\Score_Gauss.csv" [1]=> string(16) "Perdas\teste.csv" }

Output via CLI:

array(0){}

Any idea why this might be happening?

  • 1

    The code is correct, I would do otherwise but the code would be too big. Is the server you’re running on your machine? Maybe it lacks part of the directory path (PATH), a level above probably does not exist CSV files and therefore lists 0 arrays.

  • Man, I can’t believe it. Your question got me thinking why one works and the other doesn’t. It turns out that in the browser who manages the path is my IIS, ie I use the relative path, while in the CLI I need to use the full path ! How do I mark your answer as correct?

  • 1

    Sorry, you can only evaluate comments (different from replies) when you have reputação necessary, yet I will put as an answer.

  • I find it incredible how many people correct the text, but they don’t give an idea of how to solve the problem. A guy had the moral to correct removing the "Hello", as if this was decisive factor for the good understanding of the problem.

  • Relax. I’m new here, too, but I understand that their level is to benefit the community. Making topics as standard as possible. They randomly review topics which gives them points as well. Now changing the subject. I hope my answer has solved your problem. If yes please mark it as the correct answer on the sign visa. Hug

1 answer

1


The code is correct, I would do otherwise but the code would be too big. Is the server you’re running on your machine? Maybe it lacks part of the directory path (PATH), a level above probably does not exist CSV files and therefore lists 0 arrays.

For example, on the server the file path may vary:

/htdocs/www/

On your machine it can be:

C:\xampp\www

Browser other questions tagged

You are not signed in. Login or sign up in order to post.