#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    52
    Rep Power
    16

    Question Image upload and creation script problem, help needed.


    Hi there,
    Can any one tell me where I am going wrong, Iíve spend my past three days working on this part of the script.
    What I am trying to do is to upload an image Jpeg, the script is meant to resize the image to a specified size from any Size. And it copies to a folder. It also creates a thumbnail image and stores it in another folder.
    It executes the first part but the second thumbnail creation I am getting an error, I tried every thing but I can't understand where I am going wrong.
    Here is the error message:
    Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/repor_images//' for writing in uploadtest_pro.php
    And hereis the script:
    PHP Code:
    $uploaddir='../images/repor_images/'// Uploaded images directory on the server
    $b_image1 $_FILES['image1']['name'];    // New name of the file just created from the tempname.
    $folderthumb='../images/repor_images/thumb/';
    error_reporting(E_ALL);
    // Image1
    if 
        (
    move_uploaded_file($_FILES['image1']['tmp_name'], $uploaddir.$b_image1)) {
            if (!
    $max_width)
                
    $max_width 360;
                    if (!
    $max_height)
                        
    $max_height 360;
                        
    $size GetImageSize($uploaddir.$b_image1);
                        
    $width $size[0];
                        
    $height $size[1];
                        
    $x_ratio $max_width $width;
                        
    $y_ratio $max_height $height;
                            if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
                                
    $b_width1 $width;
                                
    $b_height1 $height;
                            }
            else if ((
    $x_ratio $height) < $max_height) {
                
    $b_height1 ceil($x_ratio $height);
                
    $b_width1 $max_width;
            }
            else {
                
    $b_width1 ceil($y_ratio $width);
                
    $b_height1 $max_height;
            }
        
    $src_img imagecreatefromjpeg("$uploaddir/$b_image1");//source of the image
        
    echo($src_img);
        
    $dst_img imagecreatetruecolor($b_width1,$b_height1);// destination of the normal size image
        
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$b_width1,$b_height1,$width,$height);
        
    imagejpeg($dst_img,"$uploaddir/$b_image1",80);// New normal sized image
        
    // Thumbnail 1
            
    if (!$tn_max_width)
                
    $tn_max_width 104;
                    if (!
    $tn_max_height)
                        
    $tn_max_height 104;
                        
    $tn_size GetImageSize("$uploaddir/$b_image1");
                        
    $tn_width $tn_size[0];
                        
    $tn_height $tn_size[1];
                        
    $tn_x_ratio $tn_max_width $tn_width;
                        
    $tn_y_ratio $tn_max_height $tn_height;
                            if ( (
    $tn_width <= $tn_max_width) && ($tn_height <= $tn_max_height) ) {
                                
    $tn_width1 $tn_width;
                                
    $tn_height1 $tn_height;
                            }
            else if ((
    $tn_x_ratio $tn_height) < $max_height) {
                
    $tn_height1 ceil($tn_x_ratio $tn_height);
                
    $tn_width1 $tn_max_width;
            }
            else {
                
    $tn_width1 ceil($tn_y_ratio $tn_width);
                
    $tn_height1 $tn_max_height;
            }
        
    $tn_src_img imagecreatefromjpeg("$uploaddir/$b_image1");//source of the image
        
    echo($tn_src_img);
        
    $tn_dst_img imagecreatetruecolor($tn_width1,$tn_height1);// destination of the normal size image
        
    imagecopyresampled($tn_dst_img,$tn_src_img,0,0,0,0,$tn_width1,$tn_height1,$tn_width,$tn_height);
        
    imagejpeg($tn_dst_img,"$uploaddir/$tn_image1",80);// New Thumbnail sized image
            

    Thanks in advance for any help and guidence.

    GD
    Last edited by Geckodeep; April 17th, 2003 at 06:34 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Germany
    Posts
    233
    Rep Power
    16
    hmmm just curious...

    Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/repor_images//' for writing in uploadtest_pro.php

    isnt the $uploaddir variable missing here???
    ../images/repor_images//
    --> ../images/repor_images/$uploaddir
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    In a constant state of turmoil
    Posts
    855
    Rep Power
    87
    Your not setting a value for $tn_image1 anywhere in your script that I can see. It could be the cause of the error.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    52
    Rep Power
    16
    First of all thanks to both of you Winddancer and butcher for having looked at my script, indeed Winddancer was right in terms of the upload folder.
    It was my mistake during my different tests and just before posting it I forgot to change the script back to its actual state. The variable isnít $uploaddir but it is $folderthumb (thumbnail folder), now Iíve changed it and I am still getting the same error.
    Butcher mentioned about not setting the$tn_image1 variable, Iíve tried setting it and still having the same error.
    This is error :
    Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/repor_images/thumb//' for writing in uploadtest_pro.php

    and this is the modified area of the script :
    PHP Code:
    $uploaddir='../images/repor_images/'// Uploaded images directory on the server
    $b_image1 $_FILES['image1']['name'];    // New name of the file just created from the tempname.
    $tn_image1 $_FILES['$b_image1']['name']; 
    $folderthumb='../images/repor_images/thumb/';
    ...
    ......
    imagejpeg($tn_dst_img,"$folderthumb/$tn_image1",80);// New Thumbnail sized image 
  8. #5
  9. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Jun 2002
    Location
    Washington, DC
    Posts
    2,692
    Rep Power
    26
    Ok - first, change your dir paths to reflect absolute paths. Although should'nt be required, it is a bad habit to get into. That is the first thing that sticks out by looking at your code. Example:
    PHP Code:
    /*************************
    Not Good:
    *************************/
    $uploaddir='../images/repor_images/';
    $folderthumb='../images/repor_images/thumb/';
    /*************************
    Good:
    *************************/
    $uploaddir $_SERVER['DOCUMENT_ROOT'] . '/path/to/images/repor_images/';
    $folderthumb $_SERVER['DOCUMENT_ROOT'] . '/path/to/images/repor_images/thumb/'
    Then - once you do that, change the below ->
    PHP Code:
    /*************************
    Change this:
    *************************/
    imagejpeg($tn_dst_img,"$folderthumb/$tn_image1",80);
    /*************************
    To this:
    *************************/
    imagejpeg$tn_dst_img$folderthumb $tn_image180 ); 
    Your main problem looks like it is in the imagejpeg() function as the path you specified you were double slashing (//).

    Let me know the outcome...
    ~ Joe Penn
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    52
    Rep Power
    16
    Hi Joe

    I did what you advised me to do and unfortunately I am getting the same error.
    I double checked every thing including the path etc and to me it all looks ok.
    Very strange, itís got o be some stupid syntax error or something.
    Iíve checked the brackets for opening and closing and it looks fine to me.
    Here is the code that i modified.
    PHP Code:
    $uploaddir $_SERVER['DOCUMENT_ROOT'] . 'images/repor_images/';
    $folderthumb $_SERVER['DOCUMENT_ROOT'] . 'images/repor_images/thumb/';
    $b_image1 $_FILES['image1']['name'];    // New name of the file just created from the tempname.
    $tn_image1 $_FILES[$uploaddir.$b_image1]['name'];
    error_reporting(E_ALL);
    // Image1
    if 
        (
    move_uploaded_file($_FILES['image1']['tmp_name'], $uploaddir.$b_image1)) {
            if (!
    $max_width)
                
    $max_width 360;
                    if (!
    $max_height)
                        
    $max_height 360;
                        
    $size GetImageSize($uploaddir.$b_image1);
                        
    $width $size[0];
                        
    $height $size[1];
                        
    $x_ratio $max_width $width;
                        
    $y_ratio $max_height $height;
                            if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
                                
    $b_width1 $width;
                                
    $b_height1 $height;
                            }
            else if ((
    $x_ratio $height) < $max_height) {
                
    $b_height1 ceil($x_ratio $height);
                
    $b_width1 $max_width;
            }
            else {
                
    $b_width1 ceil($y_ratio $width);
                
    $b_height1 $max_height;
            }
        
    $src_img imagecreatefromjpeg($uploaddir.$b_image1);//source of the image
        
    echo($src_img);
        
    $dst_img imagecreatetruecolor($b_width1,$b_height1);// destination of the normal size image
        
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$b_width1,$b_height1,$width,$height);
        
    imagejpeg($dst_img,$uploaddir.$b_image1,80);// New normal sized image
        
    // Thumbnail 1
            
    if (!$tn_max_width)
                
    $tn_max_width 104;
                    if (!
    $tn_max_height)
                        
    $tn_max_height 104;
                        
    $tn_size GetImageSize($uploaddir.$b_image1);
                        
    $tn_width $tn_size[0];
                        
    $tn_height $tn_size[1];
                        
    $tn_x_ratio $tn_max_width $tn_width;
                        
    $tn_y_ratio $tn_max_height $tn_height;
                            if ( (
    $tn_width <= $tn_max_width) && ($tn_height <= $tn_max_height) ) {
                                
    $tn_width1 $tn_width;
                                
    $tn_height1 $tn_height;
                            }
            else if ((
    $tn_x_ratio $tn_height) < $max_height) {
                
    $tn_height1 ceil($tn_x_ratio $tn_height);
                
    $tn_width1 $tn_max_width;
            }
            else {
                
    $tn_width1 ceil($tn_y_ratio $tn_width);
                
    $tn_height1 $tn_max_height;
            }
            echo(
    $tn_width1."<br>"); // Line for debugging
            
    echo($tn_height1."<br>"); // Line for debugging
        
    $tn_src_img imagecreatefromjpeg($uploaddir.$b_image1);//source of the image
        
    echo("$tn_src_img"."<br>");// Line for debugging
        
    echo($uploaddir.$b_image1);// Line for debugging
        
    $tn_dst_img imagecreatetruecolor($tn_width1,$tn_height1);// destination of the normal size image
        
    imagecopyresampled($tn_dst_img,$tn_src_img,0,0,0,0,$tn_width1,$tn_height1,$tn_width,$tn_height);
        
    imagejpeg($tn_dst_img,$folderthumb $tn_image1,80);// New Thumbnail sized image
        
    echo($folderthumb.$tn_image1);// Line for debugging 
    And here is the error message :
    Warning: imagejpeg() [function.imagejpeg]: Unable to open '/www/images/repor_images/thumb/' for writing in uploadtest_pro.php on line 82
    Thanks again
    GD
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Germany
    Posts
    233
    Rep Power
    16
    Originally posted by Geckodeep

    Warning: imagejpeg() [function.imagejpeg]: Unable to open '/www/images/repor_images/thumb/' for writing in uploadtest_pro.php on line 82
    Thanks again
    GD [/B]
    Maybe I am wrong, but this error message is missing the file you want to open! for example test.jpg or whatever you call your current file.

    Is it possible that the image file name is missing in your include command???

    should be the $tn_image1 right?
    seems to be empty!?
  14. #8
  15. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Jun 2002
    Location
    Washington, DC
    Posts
    2,692
    Rep Power
    26
    Hi Joe

    I did what you advised me to do and unfortunately I am getting the same error.
    Well, no - you are getting a slightly different message ->
    /************
    Old
    ************/
    Warning: imagejpeg() [function.imagejpeg]: Unable to open '../images/repor_images/thumb//'
    /************
    New
    ************/
    Warning: imagejpeg() [function.imagejpeg]: Unable to open '/www/images/repor_images/thumb/
    Now - look at your path - is that including your document root? It don't look like it from here.

    winddancer pointed out correctly the problem - you are not specifying the image or the $tn_image1 scalar is empty when executing the imagejpeg() function...
    ~ Joe Penn
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    52
    Rep Power
    16

    Thumbs up


    First of all my apologies for having not replied to the post as quickly as possible.
    Easter vacation etc., now that's done.

    So back to the topic,
    Again Thanks to both Joe pen and Winddanser. As always, you guys where right i messed around with variable naming issue,and wasted nearly two weeks on that. Until when i requested help to Joe.
    Now that's sorted.

    Honestly i still wonder how you guys find time to help people like us and keep up with your own project.
    So thanks guys and keep up the good work.
    I'll pay you a bear, just let me know when and how.

    Thanks again

    GD
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sheffield, U.K.
    Posts
    2
    Rep Power
    0

    Also watch out for file access


    I had a similar problem - but it occured when moving from one host to another. Turned out it was the file permissions!

    So always check that your file access is setup correctly (I ended up just chmod 777 the directory - lazy me).

    Hope this helps someone

    Andy Stratton

IMN logo majestic logo threadwatch logo seochat tools logo