Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP File Handling with PHP Basic File Handling Reading Files

Array issues

Whenever I execute my code on the task, it is saying that the array is empty, may you please advice on why and how to proceed with the task

//add code here
$files = file('example');
Victoria Loisi
Victoria Loisi
7,070 Points

Hello there, Have you tried using 'var_dump($files)' to check what it has inside?

1 Answer

Jonathan Love
Jonathan Love
4,784 Points

Your array variable is empty because you declared it but you didn't do anything with it.

You have to use one of the PHP directory functions to look for the files. Go to the first video and and take a look at the teacher's notes and also take a look at the "File Handling Cheat Sheet".

  • chdir — Change directory
  • chroot — Change the root directory
  • closedir — Close directory handle
  • dir — Return an instance of the Directory class
  • getcwd — Gets the current working directory
  • opendir — Open directory handle
  • readdir — Read entry from directory handle
  • rewinddir — Rewind directory handle
  • * scandir — List files and directories inside the specified path *