Jump to content

[SOLVED] File locking with ImagePng


andy75180

Recommended Posts

Hi ya,

 

Am currently creating an image using PHP and saving the finished image onto my server using ImagePng($IMAGE,$FILENAME);

 

This works fine, and the image can then be retreived using normal <img> in my XHTML code.

 

I'm now wondering if a problem could occur if a person was getting the image by refreshing their browser and at the same time another person was creating the image file using an automatic PHP script. Does the file need to be write locked in anyway using flock?

 

Any help most appricated. Thankyou

 

Link to comment
https://forums.phpfreaks.com/topic/60618-solved-file-locking-with-imagepng/
Share on other sites

No the image isn't user specfic, it will be on my homepage, so will be viewed quite a bit.

 

Sounds like I need some sort of file locking then, but not sure how to do it using the normal 'flock' function, because I'm not writing the image to disk using the 'fwrite' command, only the 'imagepng' function which is different.

 

Any idea anyone?

is the image going to be differet every single view?

 

alternatively you can use the on-the fly method

 

<img src="/path/to/image_script.php?anyvars=put-here" />

 

then in your image_script.php you can generate the image - that way it will never have to be saved on the server and anyone else viewing the page will not interfer with the image you are currently/about to display...

Excellent, I tried to do an on-the-fly image, but was unable to do it. Being a dumb dumb, I've realised I missed out the

header('Content-type: image/png'); command.

 

It now works fine. Also is quicker, because don't have to save and retrieve it from the server.

 

Thankyou very much, everyone that helped.

 

Good programming....

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.