How to get the execution status of a copy function in PHP?

I need to know how to get copy() function status in PHP.

I use this function to upload a remote file, and I want a progress bar for this program.

+7
source share
2 answers

You will need to write your own copy function. First check the file size with an HTTP HEAD request, for example with this solution:

http://php.net/manual/en/function.filesize.php#92462

Then do this to extract the file:

 $remote = fopen('remote-file', 'r'); $local = fopen('local-file', 'w'); $read_bytes = 0; while(!feof($remote)) { $buffer = fread($remote, 2048); fwrite($local, $buffer); $read_bytes += 2048; //Use $filesize as calculated earlier to get the progress percentage $progress = min(100, 100 * $read_bytes / $filesize); //you'll need some way to send $progress to the browser. //maybe save it to a file and then let an Ajax call check it? } fclose($remote); fclose($local); 
+15
source

You cannot get a progress bar to call copy() to my knowledge.

+1
source

All Articles