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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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