Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // URL: http://snipplr.com/
- // URL: http://www.mechanicmatt.com/
- // so lets say you saved this script in your document root as "dlFile.php". so it's located at yourdomain.com/dlFile.php
- //
- // and your files are located at yourdomain.com/files/
- //
- // then you would link to it like this
- //
- // href="dlFile.php?filename=podcast1.mp3". If your file is in a subdirectory of /files/ then you'd use
- //
- // dlFile.php?filename=subDir/filename.jpg
- //
- // Refer to the comment in the php script to specify the path where the files are stored.
- <?php
- if ($_REQUEST["filename"] != "") {
- $filename = str_replace("../", "", $_REQUEST["filename"]);
- if ($filename != "") {
- /*
- this is where you set the base path and the file for security reasons.
- If you wish to manually hard code a base path, then comment out the following line,
- and use the line after it
- */
- $file = dirname(__FILE__) . "/files/" . $filename;
- //$file = "/var/www/htdocs/audio/" . $filename;
- if (file_exists($file)) {
- header ("Content-type: octet/stream");
- header ("Content-disposition: attachment; filename=" . str_replace(" ", "_", basename($file)) . ";");
- header ("Content-Length: " . filesize($file));
- readfile($file);
- die();
- }
- else {
- echo '
- <script type="text/javascript">
- <!--
- alert("' . $file . '\n\nI do not currently have this image ready for download");
- -->
- </script>
- ';
- }
- } else {}
- } else {}
- ?>
Add Comment
Please, Sign In to add comment