Hi:

I have a process allowing the admin to view users information and download files that the user uploaded to MySQL.
When the admin clicks on the file link in the admin page, I expect the file will display using the default program (i.e. pdf or txt), or download (i.e. MSWord).

The admin panel is at:
http://development.products-and-services.ca/cms/users.php

The files listed can be retreived and viewed using right-click -> save as -> change the ext to the correct type, but when I single-left click the link, I get binary screen output.

I am suspecting a mime-type issue, but do not know enough about this area.

Any suggestions would be great.

Thanks in advance,
dennishall

<?

//error_reporting(E_ALL);
//ini_set('display_errors', '1');

include "../contact/reg_dbc.php";
$id = $_GET['id'];
$query = "SELECT name, type, size, content " . "FROM subscribers WHERE id = '$id'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");

echo $content;

mysql_close();
exit;

?>

P.S. I have this posting in PHP as well, but it seems more appropriate in this forum.

I already told you that this:

list($name, $type, $size, $content) = mysql_fetch_array($result);

needs to be using mysql_fetch_assoc() , even if you get a blank screen. The blank screen is due to some other issue.

In your case, if you open firefox, go the link you provided, then click on test.php. Press CTRL+U.

Do you see that HTML <table> markup? That is your problem. You cannot send ANY output to the browser before the header() calls. Somewhere you are sending what looks like "debugging" information in a "tabular" HTML format. My guess is reg_dbc.php.

Hi hielo:

I have changed teh array to assoc again... and I resotred my file to the one above again.

The table data you saw was me running a download.php that echoed my vars out in table format so I could see my values from users.php. They are all good.

I've put the original download.php to what you see above in this thread and made your recommended assoc change.

Now CTRL+V in FF gives consistant results with IE (blank screen and an empty source view screen).

I created the tabular output to see if I was actually processing the header identifiers... I don't think it is.

Thanks,
dennishall

For your script to work, you need to use the header() function in order to send the proper headers. However, it will NOT work if you send ANY output before you call header - ex:

<?php //WRONG: There is space BEFORE the php opening tag
header(...);
...
?>

In your case, currently I am seeing:


which is typically found in utf-8 encoded files, so it is probably the text editor you are using. To clarify, basically the actual content of your php file is most likely:

<?php //WRONG: Those characters are sent to the browser before the header() output is sent
header(...);
...
?>

So, take your php code above, paste it onto Notepad and when you are saving it choose ANSI encoding. THEN upload the file again. (You may have to do the same procedure for the other php file - reg_dbc.php).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.