|
|
|
| Title : |
A PHP function to force a browser to download a given file in the web server. It's also possible to set the max download speed via a second argument.
|
| Categories : |
PHP, Filesystem |
 Alix Axel |
| Date : |
Nov 23rd 2008 |
| Grade : |
5 of 5 (graded 1 times) |
| Viewed : |
2978 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Alix Axel |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
| <?php
function Download($path, $speed = null)
{
if (is_file($path) === true)
{
set_time_limit(0);
while (ob_get_level() > 0)
{
ob_end_clean();
}
$speed = (is_null($speed) === true) ? filesize($path) : intval($speed) * 1024;
header('Expires: 0');
header('Pragma: public');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($path));
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
header('Content-Transfer-Encoding: binary');
for ($i = 0; $i <= filesize($path); $i = $i + $speed)
{
echo file_get_contents($path, false, null, $i, $speed);
flush();
sleep(1);
}
exit();
}
return false;
}
?> | | |
|
| Simple pipe delimited file export program that downloads to a local machine Categories : PHP, Filesystem, Databases, MySQL, HTTP | | | Execute a command to a string Categories : PHP, Program Execution, Filesystem | | | Fetching product details from the commission junction website using php Categories : PHP, FTP, Filesystem, Compression | | | Single-file PHP news system with automatic folder structure creation Categories : PHP, Filesystem, Arrays | | | A PHP Script that shows how to use FTP to run a shell script, read two local files and update data in a database. Categories : PHP, Filesystem, FTP, Date Time, Databases | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Read DPI value from image with PHP Categories : PHP, Graphics, Filesystem | | | directory, opendir, listfiles, files in a directory, get directory Categories : PHP, Filesystem | | | getDirArray(Path,Filter,Sorted): Returns an array of the files in a directory,
filtered by regular expression and either sorted or randomized. Good for
random pictures and graphics. Categories : PHP, Filesystem, Directories | | | Grab images from one or more URLs and save them to a specified local directory. Categories : PHP, Filesystem, Strings, Arrays | | | Listing the 10 most recently updated files in a given dir by using last-
modified variable and printing to html with link to the file Categories : PHP, Directories, Filesystem | | | The toll booth Categories : PHP, Java Script, Filesystem | | | Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS Categories : PHP, Databases, PostgreSQL, Filesystem | | | Opening and formatting text files into HTML on the fly- or HTML from templates. Categories : PHP, HTML and PHP, Filesystem | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | |
| |
| |
|