|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PHP Mysql Error
I have gotten my files to upload to but then I cannot get them to download correctly using php.
I get this error Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\wwwroot\cvsvision\downloadfile.php:3) in C:\Inetpub\wwwroot\cvsvision\downloadfile.php on line 31 and then a bunch of code. help!!! |
|
#2
|
|||
|
|||
|
Please post the parts of code that are a problem.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
this is the file that writes it to the database
<?php require_once('Connections/news.php'); ?> <?php mysql_select_db($database_news, $news); $query_Recordset1 = "SELECT * FROM market_reports"; $Recordset1 = mysql_query($query_Recordset1, $news) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //GrabFile.php: Takes the details<br> // of the new file posted as part of the form and adds it to the database db_news to the market reports table global $Report_Type; global $Date; global $fileUpload; global $fileUpload_name; global $fileUpload_size; global $fileUpload_type; echo $HTTP_POST_VARS["frmUploadFile"]; // Make sure both a description and // file have been entered if(empty($Report_type) || $fileUpload == "none") die("You must enter all information"); $fileHandle = fopen($fileUpload, "rb"); // opens up the uploaded file and reads it into the database $fileContent = fread($fileHandle, $fileUpload_size); $fileContent = addslashes($fileContent);//escapes any apostrophises and Double quotes $dbQuery = "INSERT INTO market_reports VALUES "; $dbQuery .= "(0, '$fileUpload_type', '$fileContent', '$Report_Type', '$Date' )"; mysql_query($dbQuery) or die("Couldn't add file to database"); echo "The details of the uploaded file are shown below:<br><br>"; echo "<b>File name:</b> $fileUpload_name <br>"; echo "<b>File type:</b> $fileUpload_type <br>"; echo "<b>File size:</b> $fileUpload_size <br>"; echo "<b>Uploaded to:</b> $fileUpload <br><br>"; echo "<a href='blobtry.php'>Add Another File</a>"; ?> </body> ------------------------------- Here is the file that tries to download it <?php require_once('Connections/news.php'); ?> <?php mysql_select_db($database_news, $news); $query_downloadBlob = "SELECT * FROM market_reports"; $downloadBlob = mysql_query($query_downloadBlob, $news) or die(mysql_error()); $row_downloadBlob = mysql_fetch_assoc($downloadBlob); $totalRows_downloadBlob = mysql_num_rows($downloadBlob); ?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <?PHP global $blobId; $dbQuery = "SELECT blobType, blobData "; $dbQuery .= "FROM market_reports "; $dbQuery .= "WHERE blobId = $blobId"; $result = mysql_query($dbQuery) or die("Couldn't get file list"); $fileType = @mysql_result($result, 0, "blobType"); $fileContent = @mysql_result($result, 0, "blobData"); if(mysql_num_rows($result)==1) { header(content-type: $fileType); echo $fileContent; } else { echo "Record doesn't exist."; } ?> <body> |
|
#4
|
||||
|
||||
|
You're trying to echo conflicting content-types. When you print HTML out to the screen, a Content-type: text/html header is sent by default. You're doing that and then also sending a header for the file type being downloaded. You have to pick one or the other and send only the headers you need to send. My guess is that you'll want to remove the HTML output.
|
|
#5
|
|||
|
|||
|
Here is the download file I have now.
<?php require_once('Connections/news.php'); ?> <?php mysql_select_db($database_news, $news); $query_downloadBlob = "SELECT * FROM market_reports"; $downloadBlob = mysql_query($query_downloadBlob, $news) or die(mysql_error()); $row_downloadBlob = mysql_fetch_assoc($downloadBlob); $totalRows_downloadBlob = mysql_num_rows($downloadBlob); ?> <?PHP global $blobId; $dbQuery = "SELECT blobType, blobData "; $dbQuery .= "FROM market_reports "; $dbQuery .= "WHERE blobId = $blobId"; $result = mysql_query($dbQuery) or die("Couldn't get file list"); if(mysql_num_rows($result)==1) { $fileType = @mysql_result($result, 0, "blobType"); $fileContent = @mysql_result($result, 0, "blobData"); header("Content-type: $fileType"); echo $fileContent; } else { echo "Record doesn't exist."; }?> <?php mysql_free_result($downloadBlob); ?> --------- I am still getting that error. Is there anything else I should do??? |
|
#6
|
|||
|
|||
|
Basically how do I get rid of the default html/text header????
|
|
#7
|
|||
|
|||
|
Why do you keep opening and closing your php scripts when there is no html output in between them?
You are outputting blank lines each time you do this. You need to either keep all your php code in the same <?php block or take the space out from between each block of code. |
|
#8
|
||||
|
||||
|
And, just to expand laidbak's comment and make its explanation a little more explicit, blank lines equal HTML output that's keeping your headers from working properly. If you've got extra lines above, below, or between your PHP markers, you're likely to have problems.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > PHP Mysql Error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|