Jump to content

Recommended Posts

I was playing with a snippet I found and made this if anyone wants it,

or, Any improvements would be welcome.

 

What it is is a tool for when you are developing a website that you just want to view a particular file. not ftp or anything, just view it.  like if you wanna snag it real quick.  You leave it in the folder, and call it up when you want it.  you delete it when the site is done.  It display a like to all files, and makes thumbnails of the pics for you.

 

<?php

// ************Variable****************
$uri = $_SERVER['REQUEST_URI'];
$url = substr($uri, 0, -32);
$documentroot=$_SERVER['DOCUMENT_ROOT'];
$servername=$_SERVER['SERVER_NAME'];
$path = "http://".$servername.$url;
$directory = $documentroot.$url;
$pw=sha1('nosecrets');
// ************Variable****************

// Check to see password is set
if(!isset($_GET['PASSWORD'])) {
echo "<center><br/><form name='list' action='listfiles.php'>";
echo "<input type='password' name='PASSWORD'>";
echo "<input type='submit' value='Submit'>";
echo "</form></center>";
}
elseif (sha1($_GET['PASSWORD']) != $pw) {
header('Location: listfiles.php');
}
elseif (sha1($_GET['PASSWORD']) == $pw) {
echo "<table border='1'>";
echo "<tr><td>URL PATH: ".$path."</td></tr>";
echo "<tr><td>DIRECTORY: ".$directory."</td></tr>";
if ($handle = opendir($directory)) {
   		while (false !== ($file = readdir($handle))) {
		if ($file != "." && $file != "..") {
			$test1 = substr($file, -4);
            		if (preg_match("/.jpg$/i", $file)) {
            			$filename = $path . $file;
            			echo "<tr><td><a  href='$filename'><img src='$filename' width='100' /></a><br />";
            			echo "<a  href='$filename'>$file</a></td></tr>";
            			}
            		if (preg_match("/.gif$/i", $file)) {
            			$filename = $path . $file;
            			echo "<tr><td><a  href='$filename'><img src='$filename' width='100' /></a><br />";
            			echo "<a  href='$filename'>$file</a></td></tr>";
            			}
            		if (preg_match("/.png$/i", $file)) {
            			$filename = $path . $file;
            			echo "<tr><td><a  href='$filename'><img src='$filename' width='100' /></a><br />";
            			echo "<a  href='$filename'>$file</a></td></tr>";
            			}
            		if (preg_match("/.bmp$/i", $file)) {
            			$filename = $path . $file;
            			echo "<tr><td><a  href='$filename'><img src='$filename' width='100' /></a><br />";
            			echo "<a  href='$filename'>$file</a></td></tr>";
           			}
   				else {
   	       			$filename = $path . $file;
            			echo "<tr><td><a  href='$filename'>$file</a></td></tr>";
            			}
         	}
		}
		closedir($handle);
	}
}
?>
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/54932-if-anyone-wants-it/
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.