Hi All:

I have been working very hard and long at understanding this situation. I have tried many different sample scripts, to check my work and find find my solution.

I have created a job board for a client, the user applies for a job in application form.php which then sends the user an email to authenticate them in activate.php; which allows them to upload/update their resume through the same link, and finally, I also have an admin page to manage the applicants. It ALL works great.
Now I'm trying to add the ability for the admins to download the resume files from the MySQL db and I keep getting a blank screen.

My db is set for MEDIUMBLOB - BINARY, and I see the file, type, size in the db. I can also see the 100's of lines of binary data on my screen when I enable it in the admin page.

I have ini_set('display_errors', E_ALL); set on ALL my pages to see what's up but get no errors.

As a cross check, I have tried some of the tutorial type scripts out there and get exactly the same results (blank white screen with the correct URL ...download.php?id=#

Any ideas what could be the issue here?
Anyone seen / solved this same type issue?
I'm in dyer need of feedback / assistance with this now.

Thanks in advance,
dennishall

Recommended Answers

All 8 Replies

Display_errors can only be set to 0 (off) or 1 (on), E_ALL is for the setting error_reporting.

Also some hosts disable ini_set() for security purposes, have you tried placing a php.ini file, with the single line of display_errors = 1 in the same directory of the file that's not working properly?

[Links]
http://php.net/manual/en/errorfunc.configuration.php

Nyight:

You got me, I put the wrong error reporting code in my files this time.

error_reporting(E_ALL);
ini_set('display_errors', '1');
...is the correct code.

I found my error(s) - undefined vars. Doesn't mean I'll get the results, but does mean I'm clearly too tired - at it too long today.

Thanks Nyight, I needed your input - even to remind me to stop forgetting the basics.
I look forward to your assistance when my problems are fixed and the real ones come out :).

Best Regards,
dennishall

Hi Nyight:
I have corrected my undefined vars and have things working now with the exception of the final result opening the uploaded file. I no longer get a blank screen, but instead echoing binary content in the browser.

You can see the users form at:
http://development.products-and-services.ca/cms/users.php
to get an idea of what I'm trying to accomplish.

Security is temporarily removed.

BTW: If I right-click the file links -> Save target as -> and put the correct ext on the file save, the files are correct when opened locally. Is this a mime-type issue in the header section?

Your advise would be greatly appreciated.

My download.php is as follows:

<?

//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;

?>

Is this a mime-type issue in the header section?

It sure sounds like it. On line 11, try changing:

mysql_fetch_array($result)

to:

mysql_fetch_assoc($result)

Hi hielo:

mysql_fetch_array($result); provides me the binary output to screen
mysql_fetch_assoc($result); provides me the original blank screen

Thanks for your assistance,
dennishall

use notepad and save the text with ANSI encoding. If you have a utf-8 encoded file, chance are there are some leading characters being sent to the browser before the header() function sends its output.

Hi hielo:
Thanks for this information.
I checked my script in MSWebExpression3, Dreamweaver2, and Notepad (saving as ANSI) and saw nothing unusual(no spaces or funky chars), however, I decided to put a comment on line 1 and changed my php opener to <? (to prepare it for encryption later), ran the file, saw no diff., removed the comment, ran the file again, and got a download dialogue.
So... something was there, but I could not see it in any editor - FF relects the same results as IE.

I repeated this process for users.php as well and had no change.

Your advice was definitly helpful and greatly appreciated.

Here is my code now:

<?
include "../contact/reg_dbc.php"; //Database connection
$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_assoc($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;
?>

The result of this code produces a win dialogue to download the file named "download.php" and my results when saving as (or anything else) are an empty file.

1 layer out of the way, time for the next ;)

Best Regards,
dennishall

P.S. This is the only thread I'm posting to from this point forward.

Hi hielo:

This is resolved. You can now get the correct file downloading.

I had to revert back to fetch_array to point to the filename, not the processor script.

Thanks again for ALL your well appointed help.

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.