http - PHP protected download manager -


i building small download module larger project working on, , have run bit of issue. although works small files, when browser (any browser) begins downloading larger file, loads page would, , in last few seconds "downloads" whole file (regardless of size) instantly. have gone through http 1.1 standard on , over, , seem following them letter. 1 thought instantly comes mind when php sending data client. answer should script runs - use principle in other long scripts debugging.

here relevant piece of code (there more of course, headers , output sent:

header("content-type: application/force-download"); header("content-length: $size"); header('content-disposition: attachment; filename="'.$filedata['name'].'"');     ($i=0; $i<$size; $i+=$step) {     $content = fread($file, $step);     if ($content === false)         $content = "";      echo $content; } die(); 

any ideas? have feeling obvious issue can't see staring @ block long.

thanks in advance!

here try this, function return false if passed file directory or not found. remove spaces file name not break download. possible limit download speed changing 1024 , handle files on 2gb.

<?php  function download($file){     if (file_exists($file)) {         if(is_dir($file)){return false;}         header('content-description: file transfer');         header('content-type: application/octet-stream');         header('content-disposition: attachment; filename="'.str_ireplace(' ','_',basename($file)).'"');         header('content-transfer-encoding: binary');         header('connection: keep-alive');         header('expires: 0');         header('cache-control: must-revalidate, post-check=0, pre-check=0');         header('pragma: public');         header('content-length: '.sprintf("%u", filesize($file)));          @ob_clean();         $handle = fopen($file, "rb");         $chunksize=(sprintf("%u", (filesize($file))/1024));          set_time_limit(0);         while (!feof($handle)) {             echo fgets($handle, $chunksize);             flush();         }         fclose($handle);         die;     }else{return false;}     return; } ?> 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -