CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    image editing functions - large files...?

    Hey There,

    I created a form for the users to upload images to my site.
    I added some functions that edit the files so that they resize them and then save them on to the server, so they won't take up too much space.

    The thing is, I'm able to upload every file up to about 200kb.
    Above this, and the page gets stuck - I get a browser error.
    I checked all the server settings like 'max_input_time', 'post_max_filesize', etc. and everything is ok, and i was even able to upload a 900kb .bmp file, but i can't do the same with .jpg

    I added my code to view...
    Can anyone help me here...???

    PHP Code:
    // check if the files were really uploaded //
    if (isset($_FILES['UserPhoto1']['name']) && is_uploaded_file($UserPhoto1)) {
        
    // UPLOAD & RESIZE THE IMAGES //
        //     get the image sizes //
        
    list($iwidth$iheight$type$attr) = getimagesize($UserPhoto1);
        
    $fileName1 time();
        if (
    $type == 2) {
            
    $src_img1 = @imagecreatefromjpeg($UserPhoto1); 
            
    $fileName1 .= ".jpg"
        } elseif (
    $type == 3) {
            
    $src_img1 = @imagecreatefrompng($UserPhoto1); 
            
    $fileName1 .= ".png"
        } elseif (
    $type == 1) {
            
    $src_img1 = @imagecreatefromgif($UserPhoto1); 
            
    $fileName1 .= ".gif";
        }
                
        
    // check if the file needs to be resized //
        
    if ($iwidth $MaxWidth || $iheight $MaxHeight) {
            
    $P $iheight $iwidth;
            if (
    $iheight $MaxHeight) {
                
    $NewHeight $MaxHeight;
                
    $NewWidth $NewHeight $P;
            }
            if (
    $iwidth $MaxWidth) {
                
    $NewWidth $MaxWidth;
                
    $NewHeight $NewWidth $P;
            }
        } else {
            
    $NewWidth $iwidth;
            
    $NewHeight $iheight;
        }
        
    $TmpImg1 imagecreatetruecolor($NewWidth$NewHeight);
        
    imagecopyresized($TmpImg1$src_img10000$NewWidth$NewHeight$iwidth$iheight);
        
        
    $NewFileName1 "../images/customers/".$fileName1;
        if (
    $type == 2) {
            @
    imagejpeg($TmpImg1$NewFileName1);
        } elseif (
    $type == 3) {
            @
    imagepng($TmpImg1$NewFileName1);
        } elseif (
    $type == 1) {
            @
    imagegif($TmpImg1$NewFileName1);
        }
        
        
    $UserFile1 $NewFileName1;
        

    Rate this post if you found it useful!
    10X, gilly914

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: image editing functions - large files...?

    Can you be more specific about the error message?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Dec 2006
    Location
    Atlanta, GA
    Posts
    41

    Re: image editing functions - large files...?

    and i was even able to upload a 900kb .bmp file, but i can't do the same with .jpg
    Besides the fact that your code doesn't seem to parse .bmp files, i agree with Peej, you'd need to provide the exact browser error your getting and what browser you got it in. As well as the settings for your post_max_size, max_input_time, and upload_max_filesize php.ini variables.

    I noticed you said "post_max_filesize" as this is not a valid ini variable, this may be your issue. To quote php.net:

    post_max_size integer Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size . When an integer is used, the value is measured in bytes. You may also use shorthand notation as described in this FAQ. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. <form action="edit.php?processed=1">, and then checking if $_GET['processed'] is set.
    Hope this helps,
    Zetas

  4. #4
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: image editing functions - large files...?

    I meant to include the upload_max_filesize too..

    The problem is that i don;t get any error message. If i did, I would've posted it. When I try uploading a JPEG file larger than 200kb, I don't get any error, and i don;t even get the page back with empty variables.

    All I get is the browser error (IE 7) that the page wasn't found...

    Any help...????
    Rate this post if you found it useful!
    10X, gilly914

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: image editing functions - large files...?

    Have you tried this in any other browsers? IE does have some settings in the registry that can cause reactions such as this.

    http://support.microsoft.com/default.aspx?kbid=813827
    http://support.microsoft.com/default...b;en-us;175500
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: image editing functions - large files...?

    Thanks alot PeejAvery,
    although i still do not believe that that is the problem.

    I think you aren't fully understanding the problem, mostly because i'm not describing it in the best way which is probably a result of a lack of knowledge in some areas of PHP programming on my part...


    I will continue searching for the solution myself, and when and if i find it, i'll post it here...

    Thanks Again to everyone who tried helping,
    Gilly914
    Rate this post if you found it useful!
    10X, gilly914

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: image editing functions - large files...?

    Actually, I do understand your problem. But, you didn't answer my question.

    The reason for my last post is because some browser (IE based) come with timeouts and post sending limits. Mozilla based browsers leave that to the code. I was wondering if this is the cause of the problem. Hence, I asked you to check other browsers.

    If Firefox acts the exact same way, we can go about getting better PHP code for you. If it reacts differently, you know that the problem is IE. Now do you understand my way of going about this?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: image editing functions - large files...?

    Shame on me again!...
    Okay, maybe I wasn't fully listening... Sorry...

    I think your way about going around this might be ok, but after some more testing, I found something out...

    I deleted all the image resizing functions, and now i just left a copy function that looks something like this :
    PHP Code:
    copy($_FILES['UserPhoto1']['tmp_name'], $NewFileName1); 
    And it uploads almost every jpeg file up to 2MB (known server configuration limit)!!!

    So now you tell me, can it still be a browser setting???
    This leads me to think that this must be some error PHP gets when handling with large image files...

    Please correct me if im wrong again!

    Thanks Alot, gilly914
    Rate this post if you found it useful!
    10X, gilly914

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: image editing functions - large files...?

    In that case, you are correct. It must be in your PHP. Have you tried using move_uploaded_file() to create the file on the server and then work with that as a temp image?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured