imran0 Posted June 24, 2009 Share Posted June 24, 2009 Im using php file_get_contents to download files around 5-10mb and this can take a few minutes. Is it possibly to output the progress one the page as it downloads? Like this: 10%...20%...%30... and so on... Quote Link to comment https://forums.phpfreaks.com/topic/163445-using-file_get_contents-is-there-a-way-to-output-progress/ Share on other sites More sharing options...
derping123 Posted April 17, 2014 Share Posted April 17, 2014 someone please answer this thx Quote Link to comment https://forums.phpfreaks.com/topic/163445-using-file_get_contents-is-there-a-way-to-output-progress/#findComment-1476539 Share on other sites More sharing options...
Psycho Posted April 17, 2014 Share Posted April 17, 2014 This post has over 1,000 views and no one has responded. I would assume that it is not possible - at least not with file_get_contents(). You would likely have to build some process to get the size of the file, then get chunks of the file one at a time so you can calculate the percentage complete. Of course, you can't do this at all with a single PHP script. You have to implement AJAX. A PHP script completes ALL the execution and then returns the result to the page. Quote Link to comment https://forums.phpfreaks.com/topic/163445-using-file_get_contents-is-there-a-way-to-output-progress/#findComment-1476546 Share on other sites More sharing options...
boompa Posted April 18, 2014 Share Posted April 18, 2014 (edited) Pretty sure you could do it with cURL and the CURLOPT_PROGRESSFUNCTION callback or the CURLOPT_WRITEFUNCTION callback Edited April 18, 2014 by boompa Quote Link to comment https://forums.phpfreaks.com/topic/163445-using-file_get_contents-is-there-a-way-to-output-progress/#findComment-1476577 Share on other sites More sharing options...
Psycho Posted April 18, 2014 Share Posted April 18, 2014 Pretty sure you could do it with cURL and the CURLOPT_PROGRESSFUNCTION callback or the CURLOPT_WRITEFUNCTION callback Good call. Here's a forum post with a supposed working example: http://stackoverflow.com/questions/1939029/curl-download-progress-in-php-not-working Quote Link to comment https://forums.phpfreaks.com/topic/163445-using-file_get_contents-is-there-a-way-to-output-progress/#findComment-1476596 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.