Forum Moderators: coopster
here is the code from start to finish:
<?php
$directory = "sissydoll/";
function loadMedia($dir){
echo "Current JPEGS in ". $dir."<p />";
// open specified directory
$dirHandle = opendir($dir);
$count = 0;
$returnstr = array();
while ($file = readdir($dirHandle)) {
// if not a subdirectory and if filename contains the string '.jpg'
if(!is_dir($file) && strpos($file, '.jpg')>0) {
// update count and string of files to be returned
$returnstr[$count] = $dir.$file;
$count++;
}
}
foreach($returnstr as $key => $value){
echo "<div style=\"float: left;width: auto;height: 150px;\"><a href=\"$value\"><img src=\"$value\" height=\"100px\" width=\"100px\"/></a><br />". $value. "<br /><a href=\"del.php".'?file='.$value."&dir=".$dir."\">Delete</a></div>";
}
closedir($dirHandle);}?>
<html>
<title>Photo Manager<title>
<style type="text/css">
div{margin:5px;}</style>
<body>
<div style="position:absolute; top: 10%; left:5%;">
<form enctype="multipart/form-data" action="upload.php" method="POST" name="uploader">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
Where Would You Like This File to Go?
<select name="directory">
<?php
$directories = array();
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if(is_dir($file) && $file != "." && $file != "..")
{$directory = $file."/";
$directories[$directory] = $directory;
echo "<option value=\"$file\">$file</option>";
}
}
}
?>
</select><p />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form><p/>
Click the following paths to see the pictures stored there:<p/> <?php
foreach($directories as $keys => $values)
{
echo '<a href="photo.php?dir='.$values. '">'.$values.'</a><br />';
}
echo '<p/>';
$directory = $_GET['dir'];
if($directory == "")
{$directory = "sissydoll/";}
echo $directory.'<p>';
loadMedia($directory);
?>
</div>
</body>
</html>