Downloading files
Posted: Sun May 01, 2005 4:35 pm
I have modified some code I found on here but am having a problem with it. The file is used to download a file when a link is clicked. I can get the file to start downloading with the correct name & type but not all the file downloads.
I have a column in the DB for the file size, for example 1631613 = 1.6mb. The original script used
which I assume is the problem. The whole script is now
Do I need to put the filesize part back in somehow? Also, is this a secure method of doing this, can this be made more secure?
I have a column in the DB for the file size, for example 1631613 = 1.6mb. The original script used
Code: Select all
filesize($file);Code: Select all
<?php
error_reporting(E_ALL);
include('includes/head.php');
if (isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
}
$conf = config();
$sql = "SELECT * FROM skinz_images WHERE subs_id = ".$id." AND status='1'";
$res = $database->DB_Query($sql, $skinz) or die(mysql_error());
$row = mysql_fetch_assoc($res);
$file = $conf['subs_image_path'] . $row['subs_thumb_file'];
$size = $row['subs_zsize'];
$content = $row['subs_mime'];
$name = $row['subs_download_file'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-length: $size");
header("Content-type: $content");
header("Content-Disposition: attachment; filename=$name");
readfile($file);
echo $size;
?>