MyBB Community Forums

Full Version: help with php script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi

i was wondering since a lot of people are good at php here if someone could help me with a php script( really small)

if want a php script to redirect a download request eg.

Directory Structure
--Uploads
----files
----download.php

so instead of linking xxx.com/uploads/files/*fileneame*

i can go xxx.com/uploads/download.php?filename=*filename*

or if possible place the download.php in the root

and have xxx.com/download.php?filename=*filename*

or something around those lines

Any help will be very appreciated..mo explanation of script necessary ...that bit and any changes i can do ..thanks Big Grin
I was bored:

<?php

// Download.php script

// Get the filename
$filename = $_GET["filename"];

if($filename == ""){
die("No File Specified!");
}

// Define the path to the file
$filename = "./uploads/files/".$filename;

//Check file exists...
if (file_exists($filename)){
//File Exists
header("Location: ".$filename);

}
else {
echo "File does not exist!";
die("");
}

?>

This script can be placed in the root of your site, or anywhere else that you wish. Just be sure to modify the file path to where you want things.

Also, this file will work fine for files that do not open in the browser, like .zip and .rar, however if the file opens in the browser, it will open in the browser rather than forcing a download request. That part is a bit more complex.

Hope it helps,
BMR777
Is there any particular purpose in directing it through a PHP script?
thank u very much ...exactly what i needed
thanks