Strange Problem when Process() twice

See all posts Reply

Strange Problem when Process() twice new!
by riscphree, 15 years, 9 months ago
I'm trying to create a thumbnail and an image (resized if it is too large). I am using a different upload mechanism though, swfupload.org

This code worked when I called it with a regular form, however, I have only been able to get it to either create the thumbnail or just upload the image (and if its too big, it won't resize).

I tried using Clean() in there too, that didn't seem to help much. Here is the current code that will just produce two files of the original uploaded image (no resized thumbnail and no resized image)

$handle = new Upload($_FILES['Filedata']);
if ($handle->uploaded) {
    $handle->image_convert = 'jpg';
    // lets make some changes to the images (resize, etc)
    $handle->image_resize = true;
    $handle->image_ratio_y = true;
    $handle->image_ratio_no_zoom_in = true;
    // Lets create a thumbnail! First width then height
    if($handle->image_src_x > 75){
        $handle->image_x = 75;
    }
    if($handle->image_src_y > 100){
        $handle->image_y = 100;
    }
    // lets rename this file
    $newfile = "$handle->file_src_name_body" . time();
    $newfile_p	= md5($newfile);
    $newfile_tn	= "tn" . md5($newfile);
    $handle->file_new_name_body = "$newfile_tn";
    $handle->Process("images/v");
    $thumbnail = $handle->file_dst_name;
    // done creating a thumbnail

    //$handle-> Clean();
    // lets begin with the image
    $handle->image_resize = true;
    $handle->image_ratio_y = true;
    $handle->image_ratio_no_zoom_in = true;
    // is our image too large? Lets resize
    if($handle->image_src_x >= 604){
        $handle->image_x = 604;
    }	
    if($handle->image_src_y >= 453){ 
        $handle->image_y = 453;
    }
    // end changes
    $handle->file_new_name_body = "$newfile_p";
        
    $handle->Process("images/v");
    $handle->Clean();
}
Reply
Re: Strange Problem when Process() twice new!
by colin, 15 years, 9 months ago
Don't call Clean() in between, as this will delete you source image you just uploaded.

Can you paste here the logs from the class? Actually, both logs, for the two calls to Process().Reply
Re: Strange Problem when Process() twice new!
by riscphree, 15 years, 9 months ago
After taking Clean() out, this is the log.

system information
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : /var/httpdocs:/tmp
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
- source variables
file_src_name : fail.JPG
file_src_name_body : fail
file_src_name_ext : jpg
file_src_pathname : /tmp/phpZTI7VP
file_src_mime : application/octet-stream
file_src_size : 414549 (max= 2097152)
file_src_error : 0
process file to images/v/
- file size OK
- file mime OK : application/octet-stream
- new file name ext : jpg
- new file name body : tn2970d74c1dcdf58790d74747693e08e7
- file name safe format
- destination variables
file_dst_path : images/v/
file_dst_name_body : tn2970d74c1dcdf58790d74747693e08e7
file_dst_name_ext : jpg
- no image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : tn2970d74c1dcdf58790d74747693e08e7.jpg
file_dst_pathname : images/v/tn2970d74c1dcdf58790d74747693e08e7.jpg
- tn2970d74c1dcdf58790d74747693e08e7.jpg doesn't exist already
- no image processing wanted
- process OK
process file to images/v/
- file size OK
- file mime OK : application/octet-stream
- new file name body : 2970d74c1dcdf58790d74747693e08e7
- file name safe format
- destination variables
file_dst_path : images/v/
file_dst_name_body : 2970d74c1dcdf58790d74747693e08e7
file_dst_name_ext : jpg
- no image operation, keep extension
- checking for auto_rename
- destination file details
file_dst_name : 2970d74c1dcdf58790d74747693e08e7.jpg
file_dst_pathname : images/v/2970d74c1dcdf58790d74747693e08e7.jpg
- 2970d74c1dcdf58790d74747693e08e7.jpg doesn't exist already
- no image processing wanted
- process OKReply
Re: Strange Problem when Process() twice new!
by colin, 15 years, 9 months ago
I see. So basically, the images are uploaded, but not resized. It is because the file is not detected as an image by the class. This happens when you upload via Flash, which stupidely rewrites all MIME types to application/octet-stream

I have released an experimental version to fully support Flash uploaders. Check out this news post. This version is not perfect security-wise, but at least it works.Reply
Re: Strange Problem when Process() twice new!
by riscphree, 15 years, 9 months ago
Thanks, it seems to work. Wasn't aware of the Flash rewriting MIME types. Doh.Reply