Ads

Saturday, August 1, 2015

Serve a file using php with high speed.

Learn How to serve a file using php with high speed?
Create a page download.php
 

  <?php
/**
  * @Project PKSkiET
  * @Company SkiET INC.
  * @Author Muhammad Athar
  * @Email masge.info@gmail.com
  * @Copyright 2015 */
  if($_REQUEST['action']=='download' && !empty($_REQUEST['file']))
  {
    $filess = explode('/',$_REQUEST['file']);
   foreach($filess as $filee) { $d = $filee;
    } header('Content-Type: application/octet-stream');
     header('Content-Length: ' . filesize($_REQUEST['file']));
      header('Content-Disposition: filename='.$d);
       flush(); $file = fopen($_REQUEST['file'], "r");
        while (!feof($file)) {
            // send the current file part to the browser print
            fread($file, round(1311 * 100024));
             // flush the content to the browser
             flush();
              // sleep one second
              sleep(1);
               }
               // close file stream
                fclose($file);
                 } ?>

Now open http://server/download.php?action=download&file=[your file located on your server]

No comments:

Post a Comment