/ Published in: PHP
By default Apache won't allow you to download a file over 2GB. This PHP script overcomes that along with some extra goodies.
The script will read from standard url path the file on the server to download and display the filesize along with a link to download it.
Setup:
1) Create a directory called "d" on the root of your website and name this script "index.php"
2) Create a .htaccess file with the following lines:
RewriteEngine On
RewriteBase /d/
RewriteCond %{REQUEST_DIRECTORY} !-d [NC]
RewriteRule ^(.*)$ index.php?f=$1 [L]
3) Craft a url in the format of: http://[website_url]/d/path/to/download/filename.dat
This will link to a file: http://[website_url]/path/to/download/filename.dat
If you want, you can also craft a url with a trailing "&" and it will automatically start downloading.
Example: http://[website_url]/path/to/download/filename.dat&
The script will read from standard url path the file on the server to download and display the filesize along with a link to download it.
Setup:
1) Create a directory called "d" on the root of your website and name this script "index.php"
2) Create a .htaccess file with the following lines:
RewriteEngine On
RewriteBase /d/
RewriteCond %{REQUEST_DIRECTORY} !-d [NC]
RewriteRule ^(.*)$ index.php?f=$1 [L]
3) Craft a url in the format of: http://[website_url]/d/path/to/download/filename.dat
This will link to a file: http://[website_url]/path/to/download/filename.dat
If you want, you can also craft a url with a trailing "&" and it will automatically start downloading.
Example: http://[website_url]/path/to/download/filename.dat&
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php // Use PHP to serve files too big for Apache to deliver (>2GB) function serveFile($file){ $as = $path_parts['basename']; // Exec to determine correct file size (see's bigger files than PHP can see) { // send the current file part to the browser // flush the content to the browser } } else { print "File not found"; } } $file = "../" . str_replace(array("/d/", "?f=","../"), "", trim(urldecode($_SERVER['REQUEST_URI']))); // If the last character of the URL is & then trigger for Download $download = true; // Strip off & from the end of the $file variable }else{ $download = false; } print "Click to download <a href=\"/d/?f=".$url_path."&\">".$path_parts['basename']."</a>"; print " (".$size." bytes)"; } else { print "File not found"; } } else { serveFile($file); } ?>