Okay, this script works, and when you upload the file, it takes you to the folder where the image was uploaded, but shows all of the images in that folder.
Here's the scripts:
upload1.php
<?php
$num_of_uploads=5;
?>
<form action='/guild/upload2.php' method='post' enctype='multipart/form-data'><input type='hidden' name='submitted' value='TRUE' id='<?=time();?>' >
<input type='hidden' name='MAX_FILE_SIZE' value='<?=$max_file_size;?>' >
<?php for($x=0;$x<$num_of_uploads;$x++){
$form .= "<input type='file' name='file[]'><br>";
}
$form .= "<br><input type='submit' value='Upload File'><br />
<font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
for($x=0;$x<count($file_types_array);$x++){
if($x<count($file_types_array)-1){
$form .= $file_types_array[$x].", ";
}else{
$form .= $file_types_array[$x].".";
}
}
echo($form);
?>
upload2.php
<?php
$file_types_array=array("jpg");
$max_file_size=1048576;
$upload_dir="";
function uploaderFILES($num_of_uploads=1, $file_types_array=array("JPG"), $max_file_size=1048576, $upload_dir="/guild"){
if(!is_numeric($max_file_size)){
$max_file_size = 1048576;
}
foreach($FILES["file"]["error"] as $key => $value)
{
if($FILES["file"]["name"][$key]!="")
{
if($value==UPLOAD_ERR_OK)
{
$origfilename = $FILES["file"]["name"][$key];
$filename = explode(".", $FILES["file"]["name"][$key]);
$filenameext = $filename[count($filename)-1];
unset($filename[count($filename)-1]);
$filename = implode(".", $filename);
$filename = substr($filename, 0, 15).".".$filenameext;
$file_ext_allow = FALSE;
for($x=0;$x<count($file_types_array);$x++){
if($filenameext==$file_types_array[$x])
{
$file_ext_allow = TRUE;
}
} // for
if($file_ext_allow){
if($_FILES["file"]["size"][$key]<$max_file_size){
if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
echo('<br><br><font color="blue">'.$filename."</font> was successful <br />");
}
else { echo('<br><br><font color="#FF0000">'.$origfilename."</font> was not successfully uploaded <br />");}
}
else { echo('<br><br><font color="#FF0000">'.$origfilename."</font> was too big, not uploaded <br />"); }
} // if
else{ echo('<br><br><font color="#FF0000">'.$origfilename." </font>had an invalid file extension<br />"); }
}
else{ echo('<br><br><font color="#FF0000">'.$origfilename." </font>was not successfully uploaded<br />"); } // else
}
}
} // funtion
/////////////////////////////////////////
if(isset($_POST["submitted"])){
uploaderFILES($num_of_uploads, $file_types_array, $max_file_size, $upload_dir);
}
// Close the FTP connection
ftp_close($conn_id);
?>
<?php
$imgdir = 'guild/'; // the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.'/'.$a_img[$x]);
// do whatever
$halfwidth = ceil($size[0]/2);
$halfheight = ceil($size[1]/2);
echo "<img src= '$imgdir/$a_img[$x]'>";
echo 'name: '.$a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
}
?>
So how can I make it so that it only shows the image that was just uploaded only, including it's full url, and, a link to the folder, so the user can still view all of the images in his folder?
And I ran into another problem. I had it set so each member had his own directory, where he could upload his own images, and should only be able to view his own images when he uploads his images, but I discovered that they were all going to my "images" directory, no matter what. But I want it to upload to directory of the member ("guild" in this case), which it does. But now, whenever the success page comes on, it just says that the name of the file was successfully uploaded, and doesn't show the image itself. Any help?
And if you want to try this out, and see for yourself, go here:
http://eye-candy-guild.ueuo.com/guild/upload1.php
Thank you. 🙂
Custer
Thanks. 🙂