Download script - sometime works sometime not
| From: | Gede | Date: | Wed, 07 Nov 2001 07:57:31 +0000 |
| Subject: | Download script - sometime works sometime not | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-73682@lists.php.net to get a copy of this message | ||
I run this script with
dl-file.php?file=$filename&id=$id&size=$filesize
My problem,...this script works with somefile but sometime it does not !
Is the problem related to php.ini or apache configuration ?
I use Linux RH 7.1, Apache 1.3.20, PHP 4.0.6 and MySQL.
Thank you.
Rgrds,
Gilijk
<?
/* dl-file.php
* original version : Mesut Tunga - mesut@tunga.com
***************************************************************************/
$db_host = "10.4.1.61"; // mysql server name or ip address.
$db_user = "root"; // mysql server usernamer
$db_passwd = ""; // mysql server password
$db_database = "www-db"; // mysql server database name
$db_table = "DOWNLOAD"; // mysql server table name
global $USER_ENV;
$base_dir = "/data/DATA/HSEND/".$id."/"; //nilai parameter $id diparse dari
nilai di script
//download.php
# Find the real ip adress and host of downloader #
if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
} else {
$ip = getenv('REMOTE_ADDR');
}
$host = isset($REMOTE_HOST) ? $REMOTE_HOST : @gethostbyaddr($ip);
$waktu = date("Y-m-d H:i:s"); // Today's date on 2001-05-22 18:15:16
format
# Connect mysql server and select the database
mysql_pconnect($db_host, $db_user, $db_passwd) or die(mysql_error());
mysql_select_db($db_database) or die(mysql_error());
@mysql_query("Insert Into $db_table
values(NULL,'".$id."','".$file."','".$size."','".$ip."','".$host."','".$wakt
u."')")
or die(mysql_error());
function detect_browser($variable)
{
if(eregi("(msie) ([0-9]{1,2}.[0-9]{1,3})", $variable))
{
$content = "ie";
} else {
$content = "nn";
}
return $content;
}
# Send the file to the downloaders browser #
$file_dl = $base_dir.$file;
if (detect_browser($HTTP_USER_AGENT) == "ie") {
Header("Content-Type: application/force-download");
} else {
Header("Content-Type: application/octet-stream");
}
Header("Content-Length: ".filesize($file_dl));
Header("Content-Disposition: attachment; filename=$file");
readfile($file_dl);
?>