0

Everytime I use echo readfile('./'); die; It just outputs 0, when I want it to read the files in the directory. I also tried

$files_open = readfile('./');
$original_file = explode("\n", $files_open);
print_r ($original_file);
die;

I get the same answer:

"0"

Is there another code or anything I could use to read my file? With my directory path being './' ?

  • If you try to read file, than pass file name instead of directory path. `readfile` returns number of bytes read from file... So no file, means 0 bytes read. How to get files list in dir: http://stackoverflow.com/questions/2922954/getting-the-names-of-all-files-in-a-directory-with-php – Justinas Aug 31 '16 at 13:00
  • You may want to try to use `file_get_contents`: http://php.net/manual/en/function.file-get-contents.php – Aerendir Aug 31 '16 at 13:09
  • And have a look at [the manual page of the function you are using](http://php.net/manual/fr/function.readfile.php), you will soon realise that you are using it wrong or you are not using the right function... – Al Foиce ѫ Aug 31 '16 at 13:10
  • I did file_get_contents However my output was "Array =>0" @Aerendir –  Aug 31 '16 at 13:14
  • Are you looking for `scandir`? – melpomene Aug 31 '16 at 13:29
  • Yes, it outputs what you see as it is outputting the directory as told by Justinas. You have to pass a real file and not a folder. `./` is a folder while `./your-file.txt` is a file. – Aerendir Aug 31 '16 at 15:16
  • Can you clarify what you're trying to achieve? Are you trying to read the content of every single file inside the directory as a concatenated string or return a string/array listing all the files inside your current directory so you can do some further processing? – Passer by Aug 31 '16 at 19:56

0 Answers0