View Single Post
Old 06-26-2006, 08:50 PM   #1 (permalink)
Squirrel
Junior Member
 
Join Date: Jun 2006
Posts: 1
Send a message via AIM to Squirrel Send a message via MSN to Squirrel
Default Image Uploading Script Question

Hey, I've been writing a simple PHP script that will allow members at my site to upload jpg files. Now I had a lot of problems with this script that I wrote in terms of the directories, (the images were uploading, but not to the right place), so I got the directory problem fixed, but now I keep getting the message that the file was not uploaded successfully.

There are 2 pieces to this script, upload1.php being a form for upload2.php, which contains all of the information.

Here's upload2.php:

PHP Code:
<?php
$file_types_array
=array("jpg");
$max_file_size=1048576;
$upload_dir="../guild";

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($filename015).".".$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 
'link: "my site link"'.$a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
}

?>

Can anyone help me? Because I'm not too good at PHP. This is my first script and it's driving me crazy...

EDIT: for "my site", it actually contains the link to where the image uploaded, but these forums won't allow me to post a url...

Last edited by Squirrel : 06-26-2006 at 08:52 PM. Reason: forgot something
Squirrel is offline   Reply With Quote
Sponsored Links