468,727 Members | 1,405 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

dloading php code instead of file

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($SQL, $connection))
die("Failure to retrieve file metadata:L ".$php_error);

if (mysql_num_rows($result ) != 1)
die("Not a valid file id!");

$FileObj = mysql_fetch_array($result);

// Pull the list of file inodes
$SQL = "SELECT id FROM filedata WHERE
Masterid='".$HTTP_GET_VARS[ID]."' ORDER BY id";

if (!$result = mysql_query($SQL, $connection))
die("Failure to retrieve list of file inodes");

while ($CUR = mysql_fetch_object($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=".$FileObj[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($SQL, $connection))
die("Failure to retrieve file node data");

$DataObj = mysql_fetch_object($result);
echo $DataObj->Filedata;
}
}
Jul 16 '05 #1
1 2028
A horsie named Marc demonstrated surprising intelligence and its ability
to use morse code on Tue, 09 Sep 2003 19:27:18 -0500 when it tapped
<ac**************************@posting.google.com > with its hoof:
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]."'";
sql injection opportunity
if (!$result = mysql_query($SQL, $connection))
die("Failure to retrieve file metadata:L ".$php_error);

if (mysql_num_rows($result ) != 1)
die("Not a valid file id!");

$FileObj = mysql_fetch_array($result);

// Pull the list of file inodes
$SQL = "SELECT id FROM filedata WHERE
Masterid='".$HTTP_GET_VARS[ID]."' ORDER BY id";
sql injection opportunity

if (!$result = mysql_query($SQL, $connection))
die("Failure to retrieve list of file inodes");

while ($CUR = mysql_fetch_object($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=".$FileObj[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($SQL, $connection))
die("Failure to retrieve file node data");

$DataObj = mysql_fetch_object($result);
echo $DataObj->Filedata;
}
}
}


Sorry, I can't see why it does not work. If all of the
chunks of the file refered to by $DataObj->Filedata are
from a PHP file, then the PHP file should be sent to
the browser.

Are you sure about what is in the database? Maybe the
PHP scripts were accidentally converted into HTML
at some earlier point in time.

If you suck the PHP scripts from another server using HTTP,
and insert them into a database, the HTML code is what
will be inserted.

Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Keith Dewell | last post: by
7 posts views Thread by A_StClaire_ | last post: by
19 posts views Thread by Johnny Google | last post: by
40 posts views Thread by googler | last post: by
15 posts views Thread by lxyone | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
1 post views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.