php - update the progress bar on file downloading -


i developing simple php script show progress bar on file downloading using curl library. newbie in php therefore may not following appropriate library. facing problem in php code i.e. not updating progress bar. code following:

download.html

<!doctype html public "-//w3c//dtd html 4.01//en"> <html lang="en"> <head>     <title>progress bar</title> </head> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> <script>  $(document).ready(function() {     var url =qs('url');     var phpurl= '/test/download.php?url='+url;     console.log(phpurl);     $('#randomdiv').load(phpurl);     test('start loading'); });    function qs(search_for) {         var query = window.location.search.substring(1);         var parms = query.split('&');         (var i=0; i<parms.length; i++) {             var pos = parms[i].indexof('=');             if (pos > 0  && search_for == parms[i].substring(0,pos)) {                 return parms[i].substring(pos+1);;             }         }         return "";     }      function test(str){     $('#test').html(str);     } </script> <body style="height:100px"> <!-- progress bar holder --> <div id="progress" style="height:20px;width:250px;border:1px solid #ccc;"></div> <!-- progress information --> <div id="information" style="width"></div> <div id="test"></div> <div id="randomdiv"></div> </body> </html> 

download.php

<?php echo '<script language="javascript">document.getelementbyid("information").innerhtml="start downloading"</script>'; function init(){ ob_flush(); flush(); $url = $_get['url']; // $url = 'http://www.downvids.net/downloads/0718f33cd9eb570c8ac2847173320ed5e267/'; $filename = time().'.mp4';  $file = fopen(dirname('c:/').'/temp/'.$filename,'w'); $ch = curl_init(); curl_setopt($ch, curlopt_url,$url); // curl_setopt($ch, curlopt_buffersize,128); curl_setopt($ch, curlopt_failonerror, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_progressfunction, 'progress'); curl_setopt($ch, curlopt_noprogress, false); // needed make progress function work curl_setopt($ch, curlopt_followlocation, true); // curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_file, $file); curl_setopt($ch, curlopt_useragent, $_server['http_user_agent']); $html = curl_exec($ch); curl_close($ch); fclose($file); }  function progress($download_size, $downloaded, $upload_size, $uploaded) {      if($download_size > 0){     $percent = intval($downloaded / $download_size  * 100)."%";             echo '<script language="javascript">     document.getelementbyid("progress").innerhtml="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";     document.getelementbyid("information").innerhtml="'.$percent.' row(s) processed.";     </script>';      }     ob_flush();     flush();     // sleep(3); // see effect }  echo init(); echo '<script language="javascript">document.getelementbyid("information").innerhtml="process completed"</script>';  ?> 


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -