Exussum Posted August 15, 2006 Share Posted August 15, 2006 Hey - aint used PHP in a few months and now a simple script wont work for me <?phpfunction dirlisting($folder){ //set a functionif ($handle = opendir($folder)) { // open the Folder $num = 0;while (false !== ($file = readdir($handle))) { // Make an arrayif ($file{0} != '.') { //if the file dont start with a "."$files[$num] = $file;$num++;}//End if}// End While } // End open$random= rand(0, (count($files)-1));$dir ='images/'; // where the images $ll = substr($files[$random], -1);if($ll = 'g'){header ('Content-type: image/jpeg');include ($dir . $files[$num]);}else{header ('Content-type: image/gif');@include ($dir . $files[$num]);//header ("Location: " . $dir . $files[$random]);}//end else}//end functiondirlisting($folder){ //use function?>and this error comes up <br /><b>Warning</b>: main(images/) [<a href='function.main'>function.main</a>]: failed to open stream: No such file or directory in <b>/home/exussum/public_html/sig/index.php</b> on line <b>16</b><br /><br /><b>Warning</b>: main(images/) [<a href='function.main'>function.main</a>]: failed to open stream: No such file or directory in <b>/home/exussum/public_html/sig/index.php</b> on line <b>16</b><br /><br /><b>Warning</b>: main() [<a href='function.include'>function.include</a>]: Failed opening 'images/' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in <b>/home/exussum/public_html/sig/index.php</b> on line <b>16</b><br />Any ideas on how to fix ?Thanks Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 15, 2006 Share Posted August 15, 2006 Don't know but see what happens if you change the line[code]if($ll = 'g'){[/code]to[code]if($ll == 'g'){[/code] Quote Link to comment Share on other sites More sharing options...
Exussum Posted August 15, 2006 Author Share Posted August 15, 2006 same thing - it woudnt make too much differnce atm because the pics are all jpegs atmThanks for the reply though Quote Link to comment Share on other sites More sharing options...
Exussum Posted August 16, 2006 Author Share Posted August 16, 2006 Sorry for the Bump - but has any one got any ideas ? Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 Well, it looks as if in your first while loop you are incrementing $num past the end of the array $files[] but then you are using $files[$num] later, which would give an empty string.Also, not sure if this[code]if ($file{0} != '.')[/code]is correct? Did you not mean[code]if ($file[0] != '.')[/code] Quote Link to comment Share on other sites More sharing options...
Exussum Posted August 16, 2006 Author Share Posted August 16, 2006 King arther - i corrected that since i posted - and the second bit means the First letter not the first part of the array - i get the same error though :( Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 16, 2006 Share Posted August 16, 2006 Best post the code you have now then, also what is the value being passed in and what are the contents of that directory? The only other thing I can think of would be that the while loop is not executing at all therefore the array element $files[$num] is still an empty string. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 17, 2006 Share Posted August 17, 2006 Why are you setting $dir to be something other than $folder? Also, I wouldn't include the image file. If you are returning an image to the browser, then just use file_get_contents and echo out the file.[code]<?phpfunction dirlisting($folder){ if ($handle = opendir($folder)) { $num = 0; while (false !== ($file = readdir($handle))) { if ($file{0} != '.') { $files[$num] = $file; $num++; } } } $random = rand(0, (count($files)-1)); $ll = substr($files[$random], -1); if (substr($folder, -1) != "\\") { $folder .= "\\"; } if ($ll == 'g'){ header ('Content-type: image/jpeg'); echo file_get_contents($folder . $files[$num]); } else { header ('Content-type: image/gif'); echo file_get_contents($folder . $files[$num]); }}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.