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 trialAdi Chayot
3,618 PointsCan someone point where i am getting wrong?
-
<?php
//add code here
$files = array();
$myfile = fopen("example", "r") or die("Unable to open file!");
// Output one line until end-of-file
while(!feof($myfile)) {
$line = fgets($$myfile);
array_push($files, $line);
}
echo $files;
1 Answer
Steven Parker
231,269 PointsYou're working too hard! There's a function that will give you the contents of a directory in an array all in one step.
The function's name is "scandir".
Adi Chayot
3,618 PointsAdi Chayot
3,618 PointsThank you for your answer I want to try by the long way, as i asked in this coding quastion.
Any idea why this is not working?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsIf you really want "the long way", you still need to use other directory functions (like
opendir
andreaddir
) instead of file functions (likefopen
andfgets
). And testing for the end will also be done differently. There's a Secondary Example in the Teacher's Notes section of the first video in this stage.One other issue is that you have a "$$myfile" (with an extra "$").