Jump to content

Image Upload, Fatal Error on Memory Size??


onlyican

Recommended Posts

Hi

 

I have an upload script which uploads an image then resizes

 

The error

 

Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 7776 bytes) in Dir/UploadScript.php on line 234

 

 

The code function

 

 

$strNewFileName = date("YmdHis").rand(0,5000).".".$this->strFileExt;                    $this->strNewFileName = $strNewFileName;          $strDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir.$strNewFileName;          $strTNDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir."tn_".$strNewFileName;                    move_uploaded_file($this->arrUploadFile['tmp_name'], $strDir);                    $image_p = imagecreatetruecolor($this->intNewWidth, $this->intNewHeight);                    switch($this->strFileExt){              case "jpg":                $image = imagecreatefromjpeg($strDir);                break;              case "gif":                $image = imagecreatefromgif($strDir);                break;              case "png":                $image = imagecreatefrompng($strDir);                break;          }                    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->intNewWidth, $this->intNewHeight, $this->intCurWidth, $this->intCurHeight);                                                  $blnSuccessUpload = false;                    switch($this->strFileExt){              case "jpg":                if(imagejpeg($image_p, $strTNDir)){                    $blnSuccessUpload = true;                }                break;              case "gif":                if(imagegif($image_p, $strTNDir)){                    $blnSuccessUpload = true;                }                break;              case "png":                if(imagepng($image_p, $strTNDir)){                    $blnSuccessUpload = true;                }          }          imagedestroy($image_p);          return $blnSuccessUpload;

 

 

the Line causing issues (234) is

 

                $image = imagecreatefromjpeg($strDir);

 

 

Now that image is created but the TN is not

 

//Edit

Just a note.

I have ini_set('memory_limit', 16MB);

if you notice the allocated memory is less than the memory allowed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.