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
https://forums.phpfreaks.com/topic/213992-image-upload-fatal-error-on-memory-size/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.