Forum Moderators: coopster

Message Too Old, No Replies

File download handler

How can i optimize this?

         

asantos

4:53 pm on May 30, 2006 (gmt 0)

10+ Year Member



This is the download handler for my CMS. All this code is inside a php file called get.php. If you want to download a specific file you have to link to: get.php?id=45 where 45 is the file ID in the database.


<?php
$id = $_GET['id'];
if(!is_numeric($id)) {
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
$sql = 'SELECT * FROM files WHERE id_file='.q($id);
$rs = &$cnn->Execute($sql);
if (!$rs->EOF && file_exists(DIR_UPLOAD.basename($rs->fields['filename']))) {
# File exists
header('Location: '.URL_UPLOAD.basename($rs->fields['filename']));
die();
} else {
# File doesn't exist
header('Location: '.$_SERVER['HTTP_REFERER']);
die();
}
?>

My question is, is it OK to just implement a header redirection to the file like this:
header('Location: '.URL_UPLOAD.basename($rs->fields['filename']));

Or should i use some kind of MIME header first?

frozenpeas

5:25 pm on May 30, 2006 (gmt 0)

10+ Year Member



Mime is not needed because its just like a url link to a pdf file that is as long as the fields['filename'] includes the file extension it will work fine.