How to detect the finish with file_put_contents() in php?
In PH开发者_开发知识库P, i will write (create) the file using file_put_contents($filename, $data);
This is a blocking, I/O call, so it finishes when the function call returns. The return value is the number of bytes written (upon success).
It puts everything on hold until it's over
So you could use something like this to determine when it has finished writing the file.
echo "The file's contents are now being written, please wait.";
file_put_contents($filename, $data);
echo "The file's contents have been written.";
Retrieve the Content-Length
header from the remote location first. You can use get_headers to do that. Like so:
$headers = get_headers($url, 1);
echo "To download: " . $headers['Content-Length'] . " bytes.<br />";
精彩评论