I am looking to flock() an image.
Currently I am using the following
$img = ImageCreateFromPng($img_path);
flock($img,LOCK_EX);
It seems that the GD library's file handle is not valid with flock. How can I access the image and flock the file?
I am looking to flock() an image.
Currently I am using the following
$img = ImageCreateFromPng($img_path);
flock($img,LOCK_EX);
It seems that the GD library's file handle is not valid with flock. How can I access the image and flock the file?
The function flock
only works on file handles (or stream wrappers if they support locking). So, if you want to lock an image when you read it, you'd need to open it twice:
$f = fopen($imgPath, 'r');
if (!$f) {
//Handle error (file does not exist perhaps, or no permissions?)
}
if (flock($f, LOCK_EX)) {
$img = imagecreatefrompng($imgPath);
//... Do your stuff here
flock($f, LOCK_UN);
}
fclose($f);