PHP imagejpeg() does not overwrite the image file instantly

232 Views Asked by At

PHP imagejpeg() does not overwrite an existing image file immediately. It does work, but after an indefinite amount of time, sometimes an hour or many hours later. This weird behaviour started to happen after the server was changed and upgraded to PHP7 from PHP5.

The writing permission is properly given to the file saving destination folder. Also GD is enabled.

Following is the code snippet I'm using to save an image.

/* Get original image x y*/ 
list($w, $h) = getimagesize($_FILES['file']['tmp_name']);

/* calculate new image size with ratio */ 
$ratio = max($width/$w, $height/$h); 
$h = ceil($height / $ratio); 
$x = ($w - $width / $ratio) / 2; 
$w = ceil($width / $ratio);

$path = 'profimg/'.$width.'_'.$filename;

$imgString = file_get_contents($_FILES['file']['tmp_name']); 
$tmp = imagecreatetruecolor($width, $height); 
imagecopyresampled($tmp, $image,
                           0, 0,
                           $x, 0,
                           $width, $height,
                           $w, $h); 
imagejpeg($tmp, $path, 100); 
imagedestroy($image); 
imagedestroy($tmp);

What can be the reason for this?

0

There are 0 best solutions below