Hello
I have a website where I can upload a file via a form. The uploaded
file is stored in a MySQL database. When dloading te file I get a save
as... dialog box, letting me save the file. But when it is dloaded and
I open it, it contains te HTML code of the file displayed...
Wordt thin g is - it _used_ to work so the code is OK - only some
little thing changed. Maybe the header part???
Thanks.
Here is the code:
function downLoad_files( ) {
global $HTTP_GET_VARS, $connection;
$nodelist = array();
// Pull file meta-data
$SQL = "select * from filemetadata where id = '" .
$HTTP_GET_VARS[ID]."'";
if (!$result = mysql_query($SQ L, $connection))
die("Failure to retrieve file metadata:L ".$php_erro r);
if (mysql_num_rows ($result ) != 1)
die("Not a valid file id!");
$FileObj = mysql_fetch_arr ay($result);
// Pull the list of file inodes
$SQL = "SELECT id FROM filedata WHERE
Masterid='".$HT TP_GET_VARS[ID]."' ORDER BY id";
if (!$result = mysql_query($SQ L, $connection))
die("Failure to retrieve list of file inodes");
while ($CUR = mysql_fetch_obj ect($result))
$nodelist[] = $CUR->id;
ob_end_clean();
ob_start();
// Send down the header to the client
Header ( "Content-Type: ".$FileObj[Datatype]);
Header ( "Content-Length: ".$FileObj[Size]);
Header ( "Content-Disposition: attachment;
filename=".$Fil eObj[Name]);
// Loop thru and stream the nodes 1 by 1
for ($i = 0 ; $i < count($nodelist ) ; $i++) {
$SQL = "select FileData from filedata where id =
'".$nodelist[$i]."'";
if (!$result= mysql_query($SQ L, $connection))
die("Failure to retrieve file node data");
$DataObj = mysql_fetch_obj ect($result);
echo $DataObj->Filedata;
}
}
I have a website where I can upload a file via a form. The uploaded
file is stored in a MySQL database. When dloading te file I get a save
as... dialog box, letting me save the file. But when it is dloaded and
I open it, it contains te HTML code of the file displayed...
Wordt thin g is - it _used_ to work so the code is OK - only some
little thing changed. Maybe the header part???
Thanks.
Here is the code:
function downLoad_files( ) {
global $HTTP_GET_VARS, $connection;
$nodelist = array();
// Pull file meta-data
$SQL = "select * from filemetadata where id = '" .
$HTTP_GET_VARS[ID]."'";
if (!$result = mysql_query($SQ L, $connection))
die("Failure to retrieve file metadata:L ".$php_erro r);
if (mysql_num_rows ($result ) != 1)
die("Not a valid file id!");
$FileObj = mysql_fetch_arr ay($result);
// Pull the list of file inodes
$SQL = "SELECT id FROM filedata WHERE
Masterid='".$HT TP_GET_VARS[ID]."' ORDER BY id";
if (!$result = mysql_query($SQ L, $connection))
die("Failure to retrieve list of file inodes");
while ($CUR = mysql_fetch_obj ect($result))
$nodelist[] = $CUR->id;
ob_end_clean();
ob_start();
// Send down the header to the client
Header ( "Content-Type: ".$FileObj[Datatype]);
Header ( "Content-Length: ".$FileObj[Size]);
Header ( "Content-Disposition: attachment;
filename=".$Fil eObj[Name]);
// Loop thru and stream the nodes 1 by 1
for ($i = 0 ; $i < count($nodelist ) ; $i++) {
$SQL = "select FileData from filedata where id =
'".$nodelist[$i]."'";
if (!$result= mysql_query($SQ L, $connection))
die("Failure to retrieve file node data");
$DataObj = mysql_fetch_obj ect($result);
echo $DataObj->Filedata;
}
}
Comment