SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image upload help...

    I'm have a image script that can upload up to 6 images at a time, i'm having problems with it at the mo tho... the script doesn't always save the image on to the server (Most of the time is does) but is there anyway of fixing this so it always uploads the image onto the server??

    1) Basically it loops through and checks if each file uploader is set...

    2) If it is, it then replaces spaces (" ") with ""

    3) Then is saves the image uploaded with a profileID appended to the start of the name..

    4) Then it saves each image name and path into a database for that profileID

    5) It then saves each image twice (with different sizes) into a images folder and then updates the database with the path and image name so i can use them.

    Here is the script anyway.. (It only accepts JPG format)

    PHP Code:

            <div id="imageHolder">
              <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
              <div id="imageUpload1">
                <div id="uploader1">
                  <input name="new_image1" id="new_image1" type="file" class="fileUpload" />
                </div>                  
              </div>
              <div id="imageUpload2">
                <div id="uploader2">
                  <input name="new_image2" id="new_image2" type="file" class="fileUpload" />        
                </div> 
              </div>
              <div id="imageUpload3">
                <div id="uploader3">
                  <input name="new_image3" id="new_image3" type="file" class="fileUpload" />
                </div> 
              </div>
              <div id="imageUpload4">
                <div id="uploader4">
                  <input name="new_image4" id="new_image4" type="file" class="fileUpload" />
                </div> 
              </div>
              <div id="imageUpload5">
                <div id="uploader5">
                  <input name="new_image5" id="new_image5" type="file" class="fileUpload" />
                </div> 
              </div>
              <div id="imageUpload6">
                <div id="uploader6">
                  <input name="new_image6" id="new_image6" type="file" class="fileUpload" />
                </div> 
              </div>
            <button name="submit" type="submit" class="submitButton" style="margin-left: 270px; margin-top: 1px;">Upload</button>
            </form>
        <?php
          
    if(isset($_POST['submit'])){
            for (
    $i 0$i <= 6$i++) {
              if (isset (
    $_FILES['new_image'.$i])){
                
    $info getimagesize($_FILES['new_image'.$i]['tmp_name']);
                  if (
    $info[2] != IMAGETYPE_JPEG) {
                    echo 
    "Upload Error";
                  }
                  else {
                  
    $imagename $_FILES['new_image'.$i]['name'];
                  
    $imagename str_replace(" """$imagename);
                  
    $source $_FILES['new_image'.$i]['tmp_name'];
                  
    $target "images/".$imagename;
                  
    move_uploaded_file($source$target);
     
                  
    $imagepath $imagename;
                  
    $save "images/".$userID.$imagepath
                  
    $file "images/".$imagepath

                  if (
    $save == "images/".$userID) {
                    
    // Does not save the image name in database if no image has been selected
                  
    }
                  else {
                    switch(
    $i) {
                      case 
    1:
                        
    $query "UPDATE user_details SET image1 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    2
                        
    $query "UPDATE user_details SET image2 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    3
                        
    $query "UPDATE user_details SET image3 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    4
                        
    $query "UPDATE user_details SET image4 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    5
                        
    $query "UPDATE user_details SET image5 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    6
                        
    $query "UPDATE user_details SET image6 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                    }
                  }

                  list(
    $width$height) = getimagesize($file) ; 
     
                  
    $modwidth 160
      
                  
    $modheight 140
                  
    $tn imagecreatetruecolor($modwidth$modheight) ; 
                  
    $image imagecreatefromjpeg($file) ; 
                  
    imagecopyresampled($tn$image0000$modwidth$modheight$width$height) ; 
     
                  
    imagejpeg($tn$save100); 
                  
    imagegif($tn$save100); 
                  
     
                  
    $save "images/sml_".$userID $imagepath//This is the new file you saving
                  
    $file "images/" $imagepath//This is the original file

                  
    if ($save == "images/sml_".$userID) {
                    
    // Does not save the image name in database if no image has been selected
                  
    }
                  else {
                    switch(
    $i) {
                      case 
    1
                        
    $query "UPDATE user_details SET image_small1 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    2
                        
    $query "UPDATE user_details SET image_small2 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    3
                        
    $query "UPDATE user_details SET image_small3 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    4
                        
    $query "UPDATE user_details SET image_small4 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    5
                        
    $query "UPDATE user_details SET image_small5 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    6
                        
    $query "UPDATE user_details SET image_small6 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                    }
                  }
                   
                  list(
    $width$height) = getimagesize($file) ; 
     
                  
    $modwidth 75
     
     
                  
    $modheight 75
                  
    $tn imagecreatetruecolor($modwidth$modheight) ; 
                  
    $image imagecreatefromjpeg($file) ; 
                  
    imagecopyresampled($tn$image0000$modwidth$modheight$width$height) ; 
     
                  
    imagejpeg($tn$save100) ; // last line

                  
    $save "images/smaller_".$userID$imagepath//This is the new file you saving
                  
    $file "images/" $imagepath//This is the original file
     
                  
    list($width$height) = getimagesize($file) ; 

                  if (
    $save == "images/smaller_".$userID) {
                    
    // Does not save the image name in database if no image has been selected
                  
    }
                  else {
                    switch(
    $i) {
                      case 
    1
                        break;
                      case 
    2
                        
    $query "UPDATE user_details SET image_smaller1 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    3
                        
    $query "UPDATE user_details SET image_smaller2 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    4
                        
    $query "UPDATE user_details SET image_smaller3 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    5
                        
    $query "UPDATE user_details SET image_smaller4 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                      case 
    6
                        
    $query "UPDATE user_details SET image_smaller5 = '$save' WHERE profileID = $userID";
                        
    mysql_query($query);
                        break;
                    }
                  }
     
                  
    $modwidth 48
     
                  
    $modheight 37
                  
    $tn imagecreatetruecolor($modwidth$modheight) ; 
                  
    $image imagecreatefromjpeg($file) ; 
                  
    imagecopyresampled($tn$image0000$modwidth$modheight$width$height) ; 
     
                  
    imagejpeg($tn$save100) ; // last line
              
    }
            }
            echo 
    "<script>location.href='profile.php'</script>";
          }
         }
        
    ?>
        </div>
    and the site is www.woo-mee.com can anybody help me to get this script working fine?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,443
    Mentioned
    82 Post(s)
    Tagged
    3 Thread(s)
    What is there about the images that fail? Is it always for example image number 4 or the last one ?

    First thing I would check is the image that fails could be to large as there is a maximum file size set in php.ini

    Check these two pages as there should be an error
    returned.

    http://uk3.php.net/features.file-upload
    http://uk3.php.net/manual/en/feature...oad.errors.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •