andy75180 Posted July 18, 2007 Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
zq29 Posted July 19, 2007 Share Posted July 19, 2007 I think the image would just appear corrupt or incompleted if it is trying to be viewed while being created at the same time. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 19, 2007 Share Posted July 19, 2007 if these images are user specific and you need to save them - try using a unique name for each - like the users id.png write something to clear the folder periodically and make sure you don't allow cahcing of the image. Quote Link to comment Share on other sites More sharing options...
andy75180 Posted July 19, 2007 Author Share Posted July 19, 2007 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? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 19, 2007 Share Posted July 19, 2007 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... Quote Link to comment Share on other sites More sharing options...
andy75180 Posted July 20, 2007 Author Share Posted July 20, 2007 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.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.