I have a cam that uploads images to the server. Is there a way to check if the image is completely uploaded with php? Right now I'm checking for a minimum size but the size varies so it is not real accurate.
rainborick
12:37 am on Jul 18, 2010 (gmt 0)
I don't know if there's an easy way to check the status of an FTP transfer. I'd be inclined to do a work-around like the one you've already used, but I would check the appropriate file's size and Last Modified timestamp, and loop until it stops changing for long enough to safely assume the upload is completed.
babushka
10:53 am on Jul 18, 2010 (gmt 0)
Thanks, I was afraid of that.
rocknbil
5:23 pm on Jul 19, 2010 (gmt 0)
It's not clear how it's actually being done, but this general approach **might** lead you to a solution.
When uploading large photo uploads via the web (using this as an example) what I like to do is fork a process to do the upload and use the parent to return an immediate response that contains a refreshing "task monitor." WOW, what did I just say? :-)
if ($pid=fork()) { iframe here containing script that refreshes every 5 seconds and checks for existence of $pid } else { do the upload which is identified by $pid, the process id }
In the else above, a child process is spawned and we store the process ID of the child into $pid. As long as the file is still uploading, the process ID will still exist. So the iframe script does something usefull, like checking the file size ("12345678 uploaded . . . ") and reports it in the task monitor. When the process dies, the upload is complete.
Using this concept, you should be able to determine a way to identify the process ID of your upload, doesn't matter where it comes from - regular FTP or HTTP. When the process dies, most of the time the upload is complete, unless your connection just dies.
babushka
8:02 pm on Jul 19, 2010 (gmt 0)
Thank you. I'm not doing the upload though, the camera automatically does it via ftp. Am I still able to get a pid for that?
rocknbil
9:18 pm on Jul 19, 2010 (gmt 0)
Sure, like I said, a process on the server is a process, you just need to figure out what it is. I am **guessing** the process would be the username of the FTP account (a little fuzzy, there, it may be the server's FTP program . . . .)
The way you'd figure that out is SSH to your server, then start your cam upload and make sure it's large enough to give you time to execute
ps aux -w
in the SSH window, which will give you all the currently running processes. You'll see columns, one will be the process name/handle, another will be the PID. So you'd hook it by the name/handle, the id will be the PID. Once you have those you can start programming it to check for the process by name or handle.
You may even be able to add something to your server config so that the only time your complete script runs is when that account connects to the server (also fuzzy, just throwing an idea out there.)
Disclaimer: note this is not a *sure thing* but I can't think of a reason it wouldn't work. Unless you're on a Windows server. :-)
babushka
1:32 am on Jul 20, 2010 (gmt 0)
Thank you, I'll give that a try. Very creative solution!