dbannard Posted August 14, 2011 Share Posted August 14, 2011 The code I have works only if it's in the same folder as the images. I would like to move it to another folder so as not to have a user accidently delete it. I've tried numerous things but cannot seem to get it to work in another folder. Can someone please take a look at it and see if there is a way to make it work? I would like to have it in the "code" folder and be able to make the list from the images folder. This is running on IIS 7.5 with PHP 5.3.6 Main_Folder --images --code <?php Header("content-type: application/x-javascript"); function returnimages($dirname=".") { $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $files = array(); $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ $filedate=date ("M d, Y H:i:s", filemtime($file)); echo " [$curimage, \"$file\", \"$filedate\"],\n"; $curimage++; } } echo " [\"placeholder\"]\n"; closedir($handle); } return($files); } echo "var fpslideshowvar={\n"; echo " baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n"; echo " images: [\n"; returnimages(); echo " ],\n"; echo " desc: []\n"; echo "}\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/ Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 You don't know much about PHP, or programming in general, do you? Try calling returnimages() with the relative or absolute path to your images directory. returnimages( '/c:/absolute/path/' ); // not sure on this one, could be 'c:/absolute/path/' or returnimages( '../relative/' ); Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257281 Share on other sites More sharing options...
dbannard Posted August 14, 2011 Author Share Posted August 14, 2011 I tried it but it didn't work. Thanks for the suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257286 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 Looking at your function, it will work. Your function uses old code though. I'd suggest learning the language Trivial errors such as this won't be an issue. And you'll probably want to call it using 'C:/path/to/pictures/' if you're using absolute paths. That's the way it works on Apache after testing, and I assume IIS will be similar. I know IIS allows forward slashes. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257296 Share on other sites More sharing options...
dbannard Posted August 14, 2011 Author Share Posted August 14, 2011 I am using the PHP code included within a Image Slideshow web application. When the PHP file is moved to another folder, it doesn't work. I tried all the vaiations you suggested and was unable to get it to work. If I missed something, my appologies, but I am pretty sure I did it correctly. The full program is from here. Link: http://www.javascriptkit.com/script/script2/fpslideshow/index.shtml The only thing I added to the PHP code was "php" after the "<?" as it was missing. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257342 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 I've already copy and pasted your function, and am using it successfully with a folder on my computer, using absolute paths. I get notices about depreciated functions, but that's to be expected. The issue isn't the code. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257375 Share on other sites More sharing options...
dbannard Posted August 15, 2011 Author Share Posted August 15, 2011 I've already copy and pasted your function, and am using it successfully with a folder on my computer, using absolute paths. I get notices about depreciated functions, but that's to be expected. The issue isn't the code. Can you please post exactly what modifications you made to the code? I will give it another try tomorrow. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257557 Share on other sites More sharing options...
xyph Posted August 15, 2011 Share Posted August 15, 2011 <?php //Header("content-type: application/x-javascript"); function returnimages($dirname=".") { $pattern="\.(jpg|jpeg|png|gif|bmp)$"; $files = array(); $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ $filedate=date ("M d, Y H:i:s", filemtime($dirname.$file)); // changed this line slightly echo " [$curimage, \"$file\", \"$filedate\"],\n"; $curimage++; } } echo " [\"placeholder\"]\n"; closedir($handle); } return($files); } echo "var fpslideshowvar={\n"; echo " baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n"; echo " images: [\n"; returnimages( 'D:/Pictures/Cutlass/' ); echo " ],\n"; echo " desc: []\n"; echo "}\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257733 Share on other sites More sharing options...
dbannard Posted August 15, 2011 Author Share Posted August 15, 2011 Thanks, works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/#findComment-1257810 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.