vForums Support > Programming & Coding :: Programming Discussion :: > Using dummy index to hide directory, how can i?

Using dummy index to hide directory, how can i? - Posted By ashkir (ashkir) on 2nd Feb 10 at 7:22pm
So I am hiding my images folder with a blank index.php so people cannot see it. But I love my listing when finding an image, but I have to remake the index.php file each time I rename it to see my images listing.

Is there a PHP way to make a second index in a location that only I will know about?

Re: Using dummy index to hide directory, how can.. - Posted By Michael (wrighty) on 2nd Feb 10 at 8:58pm
You could just name it
image_list.php
or something {Smile}

Re: Using dummy index to hide directory, how can.. - Posted By ashkir (ashkir) on 2nd Feb 10 at 9:33pm
 
You could just name it
image_list.php
or something {Smile}


How can I get that to automatically list all my files in it?

I constantly keep renaming it to index2.php so I can use the index, then renaming it back. I am tired of doing this.

Re: Using dummy index to hide directory, how can.. - Posted By Ross (admin) on 2nd Feb 10 at 11:18pm
Hmmm, not tried this before but you could try using a .htaccess file to restrict access to the directory for anyone other than yourself. Something like:

RewriteEngine on # Turn on the rewrite engine
RewriteCond %{SCRIPT_FILENAME} !-f # Check we're not trying to access a file
RewriteCond %{REMOTE_ADDR} !145.149.123.458 # Check it's not from your IP address
RewriteRule .+ / [L,F] # Return a "Forbidden" message and stop checking for more rules


Failing that a php file could be used to read and list the contents of the current directory.

Re: Using dummy index to hide directory, how can.. - Posted By dog199200 (dog199200) on 2nd Feb 10 at 11:27pm
The problem with that Ross is that if ashkir does not have a static ip address, as soon as it changes he will be locked out of his own site.

I suppose if you are willing to put a little extra time into things, you would always write a small login system, or something simlar, wouldn't even need to by Mysql, for something small like that, flat file would work perfectly.

Re: Using dummy index to hide directory, how can.. - Posted By Michael (wrighty) on 3rd Feb 10 at 12:32am
Just use some PHP to list the contents of the folder.... doesn't need to have any form of security really 'cause only he'll know the URL to the file! {Tongue Out}

Re: Using dummy index to hide directory, how can.. - Posted By dog199200 (dog199200) on 3rd Feb 10 at 12:41am
Actually that would work wouldn't it, in the end the list is just an array {Unsure} call the array and its content, and it would work {Unsure}

Re: Using dummy index to hide directory, how can.. - Posted By ashkir (ashkir) on 3rd Feb 10 at 12:48am
I don't know PHP to do this and don't exactly sure how to search for this.

Also! Good idea Ross, but hopping around from different internet connections will make it a pain over time.

Re: Using dummy index to hide directory, how can.. - Posted By dog199200 (dog199200) on 3rd Feb 10 at 12:54am
hmm ok try this {Tongue Out}

Code:
 
  1. <?php
  2. $dir = "Image File Directory Here";
  3.  
  4. if (is_dir($dir)) {
  5.     if ($dh = opendir($dir)) {
  6.         while (($file = readdir($dh)) !== false) {
  7.             echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
  8.         }
  9.         closedir($dh);
  10.     }
  11. }
  12. ?>
 


that will display the name and the file type, but if you wnat them linked to the images then try this:

Code:
 
  1. <?php
  2. $dir = "Image File Directory Here */dir/images/*";
  3. $url = "The URL Of The Site *http://www.yoursite.com*";
  4.  
  5.  
  6. if (is_dir($dir)) {
  7.     if ($dh = opendir($dir)) {
  8.         while (($file = readdir($dh)) !== false) {
  9.             echo "filename: <a href=\"$url\">$file</a> : filetype: " . filetype($dir . $file) . "\n";
  10.         }
  11.         closedir($dh);
  12.     }
  13. }
  14. ?>
 


I have no exactly tested this so if it doens't work let me know what it says and i'll fix it



Re: Using dummy index to hide directory, how can.. - Posted By ashkir (ashkir) on 3rd Feb 10 at 7:06pm
they give me a blank page.