Bullet19 Posted April 11, 2008 Share Posted April 11, 2008 Is there any way to check a file to see if it is fully written before trying to use/manipulate it? I have a Flex application that calls a PHP script which executes an ImageMagick function to create a thumbnail of an image. The images are uploaded at any time so there has been a few occasions where the image is uploading (incomplete) when ImageMagick tries to make the thumbnail and of course it fails. So I'm looking for a way through PHP to check if the file is fully written before trying to do anything with it. If it's not fully written, I'll ignore it and move on but I need to add this safety check in to prevent any errors. Any ideas??? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/100611-check-completeincomplete-files/ Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 What's a fully written file versus an incomplete file? Quote Link to comment https://forums.phpfreaks.com/topic/100611-check-completeincomplete-files/#findComment-514668 Share on other sites More sharing options...
Bullet19 Posted April 11, 2008 Author Share Posted April 11, 2008 What's a fully written file versus an incomplete file? A "fully written file" or whatever the freak terminology is for it is when a file has all of its bytes and information written to it as in "3,278 of 3,278 bytes" whereas an "incomplete file" or whatever the freak terminology is may have not received all of the bytes yet as in "2,192 of 3,278 bytes". It's a lot like when you're downloading or uploading a file, you know how it's sometimes not instantly complete? Well trying to use incomplete files usually doesn't work too well in any situation whether it's on your PC or a server and that's what I'm trying to avoid - it not working well because it's not a complete file. Quote Link to comment https://forums.phpfreaks.com/topic/100611-check-completeincomplete-files/#findComment-515161 Share on other sites More sharing options...
discomatt Posted April 11, 2008 Share Posted April 11, 2008 The best way to do this is to use a database... Once your PHP script has uploaded the file completely, add an entry to a db with the file name. The flex app grabs the db rows, and converts them to thumbnails. Once the conversion is complete, delete the row. Quote Link to comment https://forums.phpfreaks.com/topic/100611-check-completeincomplete-files/#findComment-515165 Share on other sites More sharing options...
Daniel0 Posted April 11, 2008 Share Posted April 11, 2008 Ah, well just check the size of the file and compare it with the expected file size. filesize() strlen() Quote Link to comment https://forums.phpfreaks.com/topic/100611-check-completeincomplete-files/#findComment-515167 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.