Php File Download Script

Php File Download Script Rating: 6,7/10 579 reviews
  1. Php Script Download File From Ftp
  2. Php File Download Script Format
  3. Free Php Script Download
if you need to limit download rate, use this code
<?php
$local_file
= 'file.zip';
$download_file = 'name.zip';
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
if(
file_exists($local_file) && is_file($local_file))
{
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($local_file));
header('Content-Disposition: filename='.$download_file);
flush();
$file = fopen($local_file, 'r');
while(!
feof($file))
{
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
fclose($file);}
else {
die(
'Error: The file '.$local_file.' does not exist!');
}
?>
Active5 years, 2 months ago

Downloading Files with PHP Normally, you don't necessarily need to use any server side scripting language like PHP to download images, zip files, pdf documents, exe files, etc. This application works mainly on the header of the PHP. This type of file download script I have used in most of my web application. When you want to download any file you need to send the file name to this application, rest of the thing PHP will handle. Find the example file and demo below.

I'm making a simple download script, where my users can download their own images etc.

But I'm having some weird problem.

She challenges Saraswatichandra to rescue Kabir. They hide the same from Danny. They inform Vidyachatur, Dugba and Guniyal that his brother, Kabir's life is in danger. Saraswatichandra and Kumud return to Vidyachatur's house. Saraswatichandra episodes 228.

When I've downloaded the file, it's having the contents from my index.php file no matter what filetype I've downloaded. My code is like so:

$r is the result from my database, where I've stored size, type, path etc. when the file is uploaded.

UPDATE

When I'm uploading and downloading *.pdf files it's working with success. But when I'm trying to download *.zip and text/rtf, text/plain it's acting weird.

By weird I mean: It downloads the full index.php file, with the downloaded file contents inside of it.

ANSWER

I copied this from http://php.net/manual/en/function.readfile.php and it's working now. It seems that : ob_clean(); did the trick! Thanks for the help everyone.

skolind
skolindskolind
9446 gold badges22 silver badges44 bronze badges

2 Answers

Try this function , or implement these headers to your code

SagarPPanchal
6,7386 gold badges29 silver badges54 bronze badges
Erdinç ÇorbacıErdinç Çorbacı

I copied this from http://php.net/manual/en/function.readfile.php and it works now. ob_clean(); did the trick. Acer travelmate 5720 drivers.

Php Script Download File From Ftp

skolindskolind

Php File Download Script Format

9446 gold badges22 silver badges44 bronze badges

Free Php Script Download

Not the answer you're looking for? Browse other questions tagged php or ask your own question.