Jump to content

Directory enumeration of images


dbannard

Recommended Posts

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";
?> 

Link to comment
https://forums.phpfreaks.com/topic/244776-directory-enumeration-of-images/
Share on other sites

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/' ); 

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.

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.

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.

<?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";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.