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 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.