SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uploading Image and thumbnail

    I am getting this error when uploading

    Warning: getimagesize(/tmp/php4Q4UkF) [function.getimagesize]: failed to open stream: No such file or directory in /home/assistan/public_html/employers/testimage.php on line 10

    Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/assistan/public_html/employers/testimage.php on line 38
    this is my script, why am I recieving this error







    PHP Code:
    <?php



    function thumbnail($fileSrc,$fileDest,$thumb_width,$thumb_height)

    {

           list(
    $width,$height,$type,$attr)=getimagesize($fileSrc);

           switch(
    $type){ 

            case 
    2:

                
    $img=imagecreatefromjpeg($fileSrc);

                
    $fileDest=$fileDest.".jpg";

                break;

            case 
    3:

                
    $img=imagecreatefrompng($fileSrc);

                
    $fileDest=$fileDest.".png";

            break;



    }



        
    $thumb imagecreatetruecolor($thumb_width,$thumb_height);

        
    imagecopyresampled($thumb,$img,10,10,10,10,$thumb_width,$thumb_height,$width,$height);

        switch(
    $type){

            case 
    2:

                
    imagejpeg($thumb,$fileDest);

                break;

            case 
    3:

                
    imagepng($thumb,$fileDest);

                break;

        }

        return 
    basename($fileDest);

    }



    function 
    upload_file() {

       
    $a="images";

       
    $b="thumb";

       
    $u_name=$_FILES['userfile']['name'];

       
    $u_tmp_name=$_FILES['userfile']['tmp_name'];

       
    $u_size=$_FILES['userfile']['size'];

       
    $u_type=$_FILES['userfile']['type'];

       
    $fname=basename($u_name);

       echo 
    $u_tmp_name;

       

       if(
    $u_size<0) die("The file size is empty.so It cannot be upload.");

           if(!
    move_uploaded_file($u_tmp_name,"$a/$fname")) die("$fname File cannot copy in this path : $a/$fname.");

                  
    thumbnail($u_tmp_name"$b/$fname",60,60) or die("bj");

           

               echo 
    "<b>File has been Uploaded.</b>"."<br>";

               echo 
    "<b>File size is.</b>".number_format($u_size)."<br>";

               echo 
    "<b>File type is.</b>".$u_type."<br>";

               echo 
    "<b>File uploading Temporary name is.</b>".$u_tmp_name."<br>";

               echo 
    "<b>File base name is.</b>".$fname."<br>";

             

       }

       

    if(isset(
    $_POST['Click'])) 

    {

        
    $sub=empty($_POST['Click'])?'':$_POST['Click'];

            if(
    $sub=="Click"

            
    upload_file();

    }





    ?>

    <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF'?>" enctype="multipart/form-data">

    <p>File Location<input name="userfile" type="file"></p>

    <p><input name="Click" type="submit" value="Click">

    </form>

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You pass the tmp_name for filename to thumbnail function, but you execute move_uploaded_file first, which removes the temp file. Pass the filename after the upload, i.e. "$a/$fname"
    Saul

  3. #3
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It appears the file ($fileSrc) you are feeding the function is not a valid file.

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice one works good, although there is a black border on the left and top side, what could cause this, also instead of resizing to 100 and 100, can i do it via &#37;?

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    imagecopyresampled($thumb,$img,10,10,10,10,$thumb_width,$thumb_height,$width,$height); 
    You sepcify the source and destination coordinates as 10x10, 10x10, perhaps that should be 0.

    As for the size, the best idea is to keep one dimension fixed and calculate the other:
    Code php:
    if($thumb_width>$thumb_height){
      $scale=$thumb_width/$width;
    }else{
      $scale=$thumb_height/$height;
    }
     
    $thumb_width=$width*$scale;
    $thumb_height=$height*$scale;
    Saul

  6. #6
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where would be the best place to put that code?

  7. #7
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just above imagecopyresampled is fine.
    Saul

  8. #8
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help

    I need to resize the image that grabs a 100, 100 from the top left, I need to actually resize the whole thing

  9. #9
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wazo View Post
    I need to resize the image that grabs a 100, 100 from the top left, I need to actually resize the whole thing
    Uhm, I don't really follow that. I thought it's a typical thumbnail generator.

    So you're saying that you need to grab a fragment of a proportional size from an original image? And resize it to 100x100?
    Saul

  10. #10
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, daemon, Its working perfectly now


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
  •