How to detect the finish with file_put_contents() in php?

我是研究僧i 提交于 2019-12-18 04:23:09

问题


In PHP, i will write (create) the file using file_put_contents($filename, $data);
It is ok, but i want to detect the finish event of process.

Currently, the page is showing loading status.
This is currently the way i can know it is finish or not.

I want to detect with the code.


回答1:


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




回答2:


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



回答3:


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 />";


来源:https://stackoverflow.com/questions/6085357/how-to-detect-the-finish-with-file-put-contents-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!