كود PHP:
if ($file['link'] == 0)
{
if (is_dir($dl->url."/ec_tmp/"))
{
if ($dh = opendir($dl->url."/ec_tmp/"))
{
// iterate over file list
while (($filename = readdir($dh)) !== false)
{
//if (preg_match("/dlver-/",$filename))
//{
@unlink($dl->url."/ec_tmp/".$filename); // secure download, delete the files
//}
}
// close directory
closedir($dh);
}
}
// hook for post-download checks
($hook = vBulletinHook::fetch_hook('dl_post_download')) ? eval($hook) : false;
$ext = strtolower(substr($dl->url.$file['url'], strrpos($dl->url.$file['url'], '.')+1));
if ($dl->renamefiles)
{
$newfilename = preg_replace('/[^\sA-Za-z0-9\&\(\)\-\_\+\{\[\}\]\,\.]+/','',$file['name']).'.'.$ext;
}
else
{
$newfilename = preg_replace('/[0-9]+-/','',$file['url']);
}
/* $random = "ec_";
for ($i = 1; $i <= 3; $i++)
{
switch(rand(1,3))
{
case 1: $random.=chr(mt_rand(48,57)); break; // 0-9
case 2: $random.=chr(mt_rand(65,90)); break; // A-Z
case 3: $random.=chr(mt_rand(97,122)); break; // a-z
}
} */
// for sites without safe mode on, create the ec_tmp folder
if (!is_dir($dl->url."/ec_tmp/"))
{
mkdir($dl->url."/ec_tmp");
}
$dlfilename = $dl->url."/ec_tmp/".$newfilename;
copy($dl->url.$file['url'],$dlfilename);
// test download code
/* $filename = $_GET['file']; */
$filename = $dlfilename;
// required for IE, otherwise Content-disposition is ignored
if (ini_get('zlib.output_compression'))
{
ini_set('zlib.output_compression', 'Off');
}
// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if ($filename == '')
{
echo "<html><head><title>DownloadsII</title></head><body>ERROR: download file NOT SPECIFIED.</body></html>";
exit;
}
else if (!file_exists($filename))
{
echo "<html><head><title>DownloadsII</title></head><body>ERROR: File not found.</body></html>";
exit;
}
switch ($file_extension)
{
case "asf": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="video/x-ms-asf"; break;
case "avi": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="video/avi"; break;
case "doc": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/msword"; break;
case "exe": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/octet-stream"; break;
case "gif": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="image/gif"; break;
case "html": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="text/html"; break;
case "htm": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="text/html"; break;
case "jpeg": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="image/jpg"; break;
case "jpg": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="image/jpg"; break;
case "mp3": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="audio/mpeg3"; break;
case "pdf": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/pdf"; break;
case "ppt": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/vnd.ms-powerpoint"; break;
case "png": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="image/png"; break;
case "wav": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="audio/wav"; break;
case "xls": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/vnd.ms-excel"; break;
case "zip": if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/zip"; break;
default: if (strstr("|".str_replace(" ","|",$vbulletin->options['ecextopen'])."|",$ext)){header("location: $dlfilename"); break;}$ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("(anti-spam-content-type:) $ctype; name=\"".basename($filename)."\";");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
// end test download code
}
else
{
header("Location: $file[url]");
exit();
}
}
}