I have a working multiple image upload. It uploads multiple pictures to my images/regular folder fine, but i also want it to resize when I upload the image. Right now, it only resizes the first one. I also want it to have a naming convention number so if my image name was bellTower, and I upload multiple under the same category, I want it be name like so: bellTower01.jpg, bellTower02.jpg, bellTower03.jpg…bellTower25.jpg. I really need help on this, I 've been stuck on this for two weeks now.
Here is my doUpload.php:
[php]<?php
session_start();
set_time_limit(300);
if($_POST[“uploadFile”] !="")
{
$counter = 24;
for ($i=1; $i<6; $i++)  
{  
  
        $fileExt = strrchr($_FILES['userfile'.$i]['name'],".");  
          
        if($fileExt != ".jpg" && $fileExt != ".gif")  
        {  
            $_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt;  
        }else  
            {  
                $fileName = $_FILES['userfile'.$i]['name'];  
                  
                if(!is_uploaded_file($_FILES['userfile'.$i]['tmp_name']))  
                {  
                    echo "Problem: possible file upload attack!";  
                    exit;  
                }  
              
            $upfile = "images/regular/".$_POST["category"].$counter.".jpg";  
              
            //this is for resize  
            $newFileName = $_POST["category"].$counter.".jpg";  
              
            while (file_exists($upfile)) {  
                          $i++;  
                          $new_counter = sprintf("%02d",$i);  
                          $file_name = substr($newFileName, 0, strlen($pic_name)-6);  
                          $file_extension = substr($newFileName, strlen($newFileName)-6, strlen($newFileName));  
                          $frand = $file_name.$new_counter.$file_extension;  
                          $upfile = "images/regular".$_POST["category"].$new_counter.".jpg";  
                    }  
                    if (isset($new_counter)) {  
                          $upfile = "images/regular/".$_POST["category"].$new_counter.".jpg";  
                          $newFileName = $_POST["category"].$new_counter.".jpg";  
                    }  
                  
            if(!copy($_FILES['userfile'.$i]['tmp_name'], $upfile))  
            {  
                echo "Problem: cannot upload file to directory.";  
                exit;  
            }  
                $_SESSION["badFileType"] = "File uploaded successfully";      
                  
                $counter++;  
                  
            } //end of file check and upload  
              
} //end of for loop  
}else
{
$_SESSION[“badFileType”] = “”;
}
        /// RESIZING IMAGE  
      
    $dir            = "./images/regular/";  
    $thdir          = "./images/th/";  
      
    $img            = $newFileName;  
      
    resizejpeg($dir, $thdir, $img, 160, 120, "thumb_");  
      
    $_SESSION["badFileType"] .= "<br>File Sucessfully Resized!";  
header(“Location: upload2.php”);
///////////////////////////////////////////////////////////
// function resizejpeg
//
//    creates a resized image based on the max width
//    specified as well as generates a thumbnail from
//    a rectangle cut from the middle of the image.
//
//    @dir    = directory image is stored in
//    @newdir = directory new image will be stored in
//    @img    = the image name
//    @max_w  = the max width of the resized image
//    @max_h  = the max height of the resized image
//    @prefix = the prefix of the resized image
//
///////////////////////////////////////////////////////////
function resizejpeg($dir, $newdir, $img, $max_w, $max_h, $prefix)
{
// set destination directory
if (!$newdir) $newdir = $dir;
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($dir.$img);
// make sure image is a jpeg
if ($or_t == 2)
{
   // obtain the image's ratio  
   $ratio = ($or_h / $or_w);  
   // original image  
   $or_image = imagecreatefromjpeg($dir.$img);  
   // resize image?  
   if ($or_w > $max_w || $or_h > $max_h) {  
       // resize by height, then width (height dominant)  
       if ($max_h < $max_w) {  
           $rs_h = $max_h;  
           $rs_w = $rs_h / $ratio;  
       }  
       // resize by width, then height (width dominant)  
       else {  
           $rs_w = $max_w;  
           $rs_h = $ratio * $rs_w;  
       }  
       // copy old image to new image  
       $rs_image = imagecreatetruecolor($rs_w, $rs_h);  
       imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);  
   }  
   // image requires no resizing  
   else {  
       $rs_w = $or_w;  
       $rs_h = $or_h;  
       $rs_image = $or_image;  
   }  
   // generate resized image  
   imagejpeg($rs_image, $newdir.$prefix.$img, 100);  
   return true;  
}
// Image type was not jpeg!
else
{
return false;
}
}
?>[/php]
Here is my upload.php page:
[php]<?php
session_start();
echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
?>
Lab 08 - Upload2
<?php include("includes/menu.php"); ?> Upload Multiple Files- Category:
 - File 1: *
 - File 2: *
 - File 3: *
 - File 4: *
 - File 5: *