is this code is ok for downloading any size of file ????

  • smiledrops
  • Student
  • Student
  • User avatar
  • Posts: 66
  • Loc: pakistan

Post 3+ Months Ago

Code: [ Select ]
session_start();
$ok = true;
if( $ok )
{
    $file_path = "http://www.example.com/files/000003.zip";
    $path_parts = pathinfo($file_path);
    $file_name = $path_parts['basename'];
    $file_name = md5($file_name.time()).'.zip';
    $file = @fopen($file_path,"rb");
    if ($file)
    {
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Type: application/zip");
        header("Content-Disposition: attachment; filename=\"{$file_name}\"");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . filesize($file_path));
        while(!feof($file))
        {
            echo fread($file, 500*1024); // for large files
            // echo readfile($file);
            flush();
            if (connection_status()!=0)
            {
                @fclose($file);
                die();
            }
        }
        @fclose($file);
        exit;
    }
    else
        echo "Invalid File Request";
}
  1. session_start();
  2. $ok = true;
  3. if( $ok )
  4. {
  5.     $file_path = "http://www.example.com/files/000003.zip";
  6.     $path_parts = pathinfo($file_path);
  7.     $file_name = $path_parts['basename'];
  8.     $file_name = md5($file_name.time()).'.zip';
  9.     $file = @fopen($file_path,"rb");
  10.     if ($file)
  11.     {
  12.         header("Pragma: public");
  13.         header("Expires: 0");
  14.         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  15.         header("Cache-Control: public");
  16.         header("Content-Description: File Transfer");
  17.         header("Content-Type: application/zip");
  18.         header("Content-Disposition: attachment; filename=\"{$file_name}\"");
  19.         header("Content-Transfer-Encoding: binary");
  20.         header("Content-Length: " . filesize($file_path));
  21.         while(!feof($file))
  22.         {
  23.             echo fread($file, 500*1024); // for large files
  24.             // echo readfile($file);
  25.             flush();
  26.             if (connection_status()!=0)
  27.             {
  28.                 @fclose($file);
  29.                 die();
  30.             }
  31.         }
  32.         @fclose($file);
  33.         exit;
  34.     }
  35.     else
  36.         echo "Invalid File Request";
  37. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 87 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.