Help with noob syntax error

Discussion in 'PHP' started by Sn@Ke, Nov 2, 2010.

  1. #1
    The whole script runs fine and uploads the images, but I cant get it to name the image file as per the input, everything I try just uploads the image as ".jpg" with no filename, but if I put in something like microtime() it names the file >.<

    Line 59 is the problem ---> $Unique=$POST_['housename']; // File name to match the input we posted


    
    <?php
    
    function imgReisize($uploadedfile, $Destination, $Thumb){
    //this is the function that will resize and copy our images
    
    // Create an Image from it so we can do the resize
    $src = imagecreatefromjpeg($uploadedfile);
    
    // Capture the original size of the uploaded image
    list($width,$height)=getimagesize($uploadedfile);
    
    // For our purposes, I have resized the image to be
    // 600 pixels wide, and maintain the original aspect
    // ratio. This prevents the image from being "stretched"
    // or "squashed". If you prefer some max width other than
    // 600, simply change the $newwidth variable
    $newwidth=600;
    $newheight=($height/$width)*600;
    $tmp=imagecreatetruecolor($newwidth,$newheight);
    
    // this line actually does the image resizing, copying from the original
    // image into the $tmp image
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    
    // now write the resized image to disk. 
    $filename = $Destination;
    imagejpeg($tmp,$filename,100);
    
    // For our purposes, I have resized the image to be
    // 150 pixels high, and maintain the original aspect
    // ratio. This prevents the image from being "stretched"
    // or "squashed". If you prefer some max height other than
    // 150, simply change the $newheight variable
    $newheight=150;
    $newwidth=($width/$height)*150;
    $tmp=imagecreatetruecolor($newwidth,$newheight);
    
    // this line actually does the image resizing, copying from the original
    // image into the $tmp image
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    
    // now write the resized image to disk. 
    $filename = $Thumb;
    imagejpeg($tmp,$filename,100);
    
    imagedestroy($src);
    imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request
    // has completed.
    
    echo "Successfully Uploaded: <img src='".$filename."'>";
    }
    
        if(isset($_POST[submit])){
         $imgNumb=1; //This the "pointer" to images
         $DestinationDir="images/";  //destination dir 
         $ThumbDir="images/thumb/";  //thumb dir here
    
           while($_FILES["img".$imgNumb][tmp_name]){
                  $Unique=$POST_['housename']; // File name to match the input we posted
                  $destination=$DestinationDir.$Unique.".jpg";
                  $thumb=$ThumbDir.$Unique.".jpg";
                  imgReisize($_FILES["img".$imgNumb][tmp_name], $destination, $thumb);
                  $imgNumb++;
           }
        }
    ?> 
    
    
    <form action="images.php" method="post" enctype="multipart/form-data" >
    House Name: <input type="text" name="housename"/><br>
    <input type="file" name="img1"/><br>
    <input type="file" name="img2"/><br>
    <input type="file" name="img3"/><br>
    <input type="submit" name="submit" value="Submit"/>
    </form>
    
    Code (markup):
    I've tried

    $GET_['housename]
    $POST_['housename']
    $POST_[housename.value]

    etc, but no luck, I know it's something simple but I'm stuck and can't think today
     
    Last edited: Nov 2, 2010
    Sn@Ke, Nov 2, 2010 IP
  2. remember123

    remember123 Peon

    Messages:
    620
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    lol

    $Unique = $_POST["housename"];


    should work
     
    remember123, Nov 2, 2010 IP
    Sn@Ke likes this.
  3. Sn@Ke

    Sn@Ke Well-Known Member

    Messages:
    334
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    155
    #3
    Thanks, I knew it was something simple... long day :(
     
    Sn@Ke, Nov 3, 2010 IP
  4. backlinkneeded

    backlinkneeded Member

    Messages:
    285
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    that happens with everyone. We are so tired to see simple stuff.
     
    backlinkneeded, Dec 22, 2010 IP