PHP imagejpeg() does not overwrite the image file instantly

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?
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.