note 111258 added to function.fread

From: Date: Thu, 31 Jan 2013 10:00:37 +0000
Subject: note 111258 added to function.fread
Groups: php.notes 
Request: Send a blank email to php-notes+get-193459@lists.php.net to get a copy of this message
I write this script for download with resume suport <?php // If user click the download link if(isset($_GET['filename'])){ // The directory of downloadable files // This directory should be unaccessible from web $file_dir="/tmp/"; // Replace the slash and backslash character with empty string // The slash and backslash character can be dangerous $file_name=str_replace("/", "", $_GET['filename']); $file_name=str_replace("\\", "", $file_name); // If the requested file is exist if(file_exists($file_dir.$file_name)){ // Get the file size $file_size=filesize($file_dir.$file_name); // Open the file $fh=fopen($file_dir.$file_name, "r"); // Download speed in KB/s $speed=5; // Initialize the range of bytes to be transferred $start=0; $end=$file_size-1; // Check HTTP_RANGE variable if(isset($_SERVER['HTTP_RANGE']) && preg_match('/^bytes=(\d+)-(\d*)/', $_SERVER['HTTP_RANGE'], $arr)){ // Starting byte $start=$arr[1]; if($arr[2]){ // Ending byte $end=$arr[2]; } } // Check if starting and ending byte is valid if($start>$end || $start>=$file_size){ header("HTTP/1.1 416 Requested Range Not Satisfiable"); header("Content-Length: 0"); } else{ // For the first time download if($start==0 && $end==$file_size){ // Send HTTP OK header header("HTTP/1.1 200 OK"); } else{ // For resume download // Send Partial Content header header("HTTP/1.1 206 Partial Content"); // Send Content-Range header header("Content-Range: bytes ".$start."-".$end."/".$file_size); } // Bytes left $left=$end-$start+1; } ?> <html> <head> <title>Home</title> </head> <body> <a href="index.php?filename=file.pdf">Download</a> </body> </html> for more information go to this website http://www.boxafzar.com ---- Server IP: 69.147.83.199 Probable Submitter: 60.50.237.80 ---- Manual Page -- http://php.net/manual/en/function.fread.php Edit -- https://master.php.net/note/edit/111258 Del: integrated -- https://master.php.net/note/delete/111258/integrated Del: useless -- https://master.php.net/note/delete/111258/useless Del: bad code -- https://master.php.net/note/delete/111258/bad+code Del: spam -- https://master.php.net/note/delete/111258/spam Del: non-english -- https://master.php.net/note/delete/111258/non-english Del: in docs -- https://master.php.net/note/delete/111258/in+docs Del: other reasons-- https://master.php.net/note/delete/111258 Reject -- https://master.php.net/note/reject/111258 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193459) next »