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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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