Hello! I'm having some troubles uploading large images to my server via a PHP form. The form asks for several pieces of information which it then stores into a separate variable for each. It then takes the file the user has specified, renames it, and uploads it to a folder on the server. Everything works great until I try to upload large images (say anything larger than 100k or so.) When I try to do it, it gets a memory error. I contacted the host and they say that it's a memory error and that they've increased my memory_limit setting for me. However, I still get the error sometimes. I was told to unset unnecessary variables and try that? Currently, the form gathers 27 separate fields, 2 of which are for the images (one for the original, the other for the thumb.) It then takes all of those variables and adds it into a table in my database. Each variable gets a minor scrubbing before being inserted: $first1=$_POST['first']; $first2 = str_replace(" "," ",$first1); $first= str_replace("'","\'",$first2); Code (markup): Any help would be great.
post the actual error, the text it generates and the lines of code above and below the line mentioned by <5> lines ...
I've found what the problem is. It's that the script fails when trying to upload images larger than 1024*768 in resolution. The thumbnail script takes the image and creates a BMP in memory to reduce it's size, crop it, then upload it. So that's where the problem is. The script reads: function loadImage($path) /* This function loads the image you want to resize. The function will return TRUE on a succes and FALSE on failure */ { if ( $this->image ) { imagedestroy($this->image); } $img_sz = getimagesize($path); switch( $img_sz[2] ){ case 1: $this->image_type = "GIF"; if ( !($this->image = imageCreateFromGif($path)) ) { return FALSE; } else { return TRUE; } break; case 2: $this->image_type = "JPG"; if ( !($this->image = imageCreateFromJpeg($path)) ) { return FALSE; } else { return TRUE; } break; case 3: $this->image_type = "PNG"; if ( !($this->image = imageCreateFromPng($path)) ) { return FALSE; } else { return TRUE; } break; case 4: $this->image_type = "SWF"; if ( !($this->image = imageCreateFromSwf($path)) ) { return FALSE; } else { return TRUE; } break; default: return FALSE; } } Code (markup): The error happens at the imageCreateFromJpeg line, or whichever line corresponds to the filetype. Any workarounds for setting the memory to resize large images or anything?
Just bumping this to see if anyone has any fix for sizing down and creating a thumbnail for an image that's larger than 1024x768 resolution.
I know it might not be an option for you, but for generating thumbnails imagemagick 'convert' is really great: http://www.imagemagick.org Anyway, have a look here: http://php.net/manual/en/function.imagecreatefromjpeg.php#64155 (and read ALL the notes!!) HTH, cheers!