Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP File Handling with PHP Basic File Handling Directory and File Structures

Teacher Russell
Teacher Russell
16,873 Points

no files

Sorry, I never do this, and don't know how to show my code. Here's the cut and paste. Nothing I do in workspaces with this course will work. It says the files are not there. I've typed exactly what she's typed, unless I'm nuts. I didn't think I was confused about any part of the lesson.

<?php

$files = scandir('data');

echo '<ul>'; foreach ($files as $file) { if (substr($file, 0, 1) != '.') { echo '<li>'; echo $file; echo '</li>'; } } echo '</ul>';

?>

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

As I posted in your previous question about the same topic, we really need to see your workspace. This is most easily shared with us by creating a snapshot. It could be that there's something wrong with the workspace or the file structure, but we can't help you troubleshoot it without seeing the workspace. I look forward to that snapshot! :sparkles:

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again! Well, the great news is that there is nothing wrong with your code! However, you created your index.php inside the data folder. And because it's relative to the place where the index.php file is, it's looking for a data folder inside the data folder and that doesn't exist.

To fix this, move your PHP file to be on the same level as the data folder. To be honest, it's probably just easiest if you copy/paste the code, collapse the data folder. then right-click in the black area and create new file, name it index.php and then paste in your code. I sometimes have problems dragging files into folders when using workspaces.

Hope this helps! :sparkles:

Bára Paulátová
Bára Paulátová
3,583 Points

Hi Jennifer,

I am having the same problem as Russell. However, I have created my index.php file outside the data file .. and it still does not work ... https://w.trhou.se/m7g9c2npgw ...

Thanks for your help. Bára

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Bára Paulátová I'm not sure what to tell you. When I fork your workspace and click the preview button, you receive the exact same results shown at 6:18 of the video. You might try clearing your browser cache in case it's loading in old (blank) data, but on my end, your code works perfectly! :sparkles:

Bára Paulátová
Bára Paulátová
3,583 Points

:) it must have been trouble with the cache or something .. when I came back to it today, it works just fine :) thanks for your support!

Teacher Russell
Teacher Russell
16,873 Points

https://w.trhou.se/8gi1dzqob0 Not sure what happened. I watched the video. Hope this works. Goodnight!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Unfortunately, the link that you have posted is private to you and temporary. The only way for us to see your workspace is if you post a snapshot of it. I included a link to how to make a snapshot in the comment above. On the upper right-hand side of your workspace is a camera icon. When you click that it will create a snapshot which you can then link here.