getrow($sql);
$file_name = $row["file_name"];
$real_name = $row["real_name"];
$attachdir = "../".$row["path"];
$temp = split("\.", $file_name);
$file_ext = $temp[count($temp)-1];
switch ($file_ext) {
case "doc":
$file_type = "application/msword";
break;
case "exe":
$file_type = "application/octet-stream";
break;
case "pdf":
$file_type = "application/pdf";
break;
case "xls":
$file_type = "application/vnd.ms-excel";
break;
case "ppt":
$file_type = "application/vnd.ms-powerpoint";
break;
case "zip":
$file_type = "application/zip";
break;
case "mp3":
$file_type = "audio/mpeg";
break;
case "jpg":
$file_type = "image/jpeg";
break;
}
}
$full_path = "@".$attachdir."original/".$file_name;
echo $full_path.$sql;
echo '
';
if(is_readable($full_path)) {
$filesize = filesize($full_path);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: " . $file_type);
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\"" . $real_name . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$filesize);
readfile("$full_path");
/*
if ($stream = fopen($full_path, 'rb')){
while(!feof($stream) && connection_status() == 0){
//reset time limit for big files
set_time_limit(0);
print(fread($stream,1024*8));
flush();
}
fclose($stream);
}
*/
/*
@$fp = fopen($full_path, 'rb');
@flock($fp, 2);
$attachment = @fread($fp, $filesize);
@fclose($fp);
echo $attachment;
*/
} else {
echo "
I/O Error: file not exist or not readable";
}
?>