473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header error when downloading file from server

20 New Member
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 40

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 41

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 42
╨╧рб▒с������� ��������� >��■  ������������� ��V����������Y ������■   ���� U���                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ье┴�[А ��°┐������0�� �����╖ ���bjbjм·м·��� ��������� ������ �4R��╬Р�╬Р� ╖


when I try to download the file, the above errors occur.I try to fix it but still got errors.Can you please help me...
Jun 4 '09 #1
11 2341
Markus
6,050 Recognized Expert Expert
This post was separated from Atli's post on Uploading to a MySQL database.

Let's have a gander at the file causing the issue. You have sent output to the browser, through one way or another, and, well, you cannot do this.

- mark
Jun 4 '09 #2
ririe
20 New Member
thanks for the explaination..
but, what should i do now??
is there any suggestion??
Jun 4 '09 #3
Markus
6,050 Recognized Expert Expert
@ririe
Like I said previously: post the sourcecode of the file that is causing the error. We are not psychic, so it would help to see the file.
Jun 4 '09 #4
ririe
20 New Member
sorry..this is the code...hope u can help me


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Connect to the database
  3. $dbLink = mysqli_connect("localhost", "root", "", "inovasi");
  4. if(mysqli_connect_errno()) {
  5.     die("MySQL connection failed: ". mysqli_connect_error());
  6. }
  7.  
  8. # Query for a list of all existing files
  9. $result = mysqli_query($dbLink, "SELECT FileID, FileName, FileMime, FileSize, Created FROM FileStorage");
  10.  
  11. # Check if it was successfull
  12. if($result) 
  13. {
  14.  
  15.     # Make sure there are some files in there
  16.     if(mysqli_num_rows($result) == 0) {
  17.         echo "<p>There are no files in the database</p>";
  18.     }
  19.     else
  20.     {
  21.         # Print the top of a table
  22.         echo "<table width='100%' border='1'><tr>";
  23.         echo "<td><b>Name</b></td>";
  24.         echo "<td><b>Mime</b></td>";
  25.         echo "<td><b>Size (bytes)</b></td>";
  26.         echo "<td><b>Created</b></td>";
  27.         echo "<td><b>&nbsp;</b></td>";
  28.         echo "</tr>";
  29.  
  30.         # Print each file
  31.         while($row = mysqli_fetch_assoc($result))
  32.         {
  33.             # Print file info
  34.             echo "<tr><td>". $row['FileName']. "</td>";
  35.             echo "<td>". $row['FileMime']. "</td>";
  36.             echo "<td>". $row['FileSize']. "</td>";
  37.             echo "<td>". $row['Created']. "</td>";
  38.  
  39.             # Print download link
  40.             echo "<td><a href='get_file.php?id=". $row['FileID'] ."'>Download</a></td>";
  41.             echo "</tr>";
  42.         }
  43.  
  44.         # Close table
  45.         echo "</table>";
  46.     }
  47.  
  48.     # Free the result
  49.     mysqli_free_result($result);
  50. }
  51. else 
  52. {
  53.     echo "Error! SQL query failed:";
  54.     echo "<pre>". $dbLink->error ."</pre>";
  55. }
  56.  
  57. # Close the mysql connection
  58. mysqli_close($dbLink);
  59. ?>
Jun 4 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
what's the code in get_file.php (where the error occurs)?
Jun 4 '09 #6
ririe
20 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Make sure an ID was passed
  3. if(isset($_GET['id']))
  4. {
  5.     # Get the ID
  6.     $id = $_GET['id'];
  7.  
  8.     # Make sure the ID is in fact a valid ID
  9.     if(!is_numeric($id) || ($id <= 0)) {
  10.         die("The ID is invalid!");
  11.     }
  12.  
  13.     # Connect to the database
  14.     $dbLink = mysqli_connect("localhost", "root", "", "inovasi");
  15.     if(mysqli_connect_errno()) {
  16.         die("MySQL connection failed: ". mysqli_connect_error());
  17.     }
  18.  
  19.     # Fetch the file information
  20.     $query = "
  21.         SELECT FileType, FileName, FileSize, FileData 
  22.         FROM fileStorage 
  23.         WHERE FileID = {$id}";
  24.  
  25.     $result = @mysqli_query($dbLink, $query)
  26.         or die("Error! Query failed: <pre>". mysqli_error($dbLink) ."</pre>");
  27.  
  28.     # Make sure the result is valid
  29.     if(mysqli_num_rows($result) == 1)
  30.     {
  31.         # Get the row
  32.         $row = mysqli_fetch_assoc($result);
  33.  
  34.         # Print headers
  35.         header("Content-Type: ". $row['FileType']);
  36.         header("Content-Length: ". $row['FileSize']);
  37.         header("Content-Disposition: attachment; filename=". $row['FileName']);
  38.  
  39.         # Print data
  40.         echo $row['FileData'];
  41.     }
  42.     else
  43.     {
  44.         echo "Error! No image exists with that ID.";
  45.     }
  46.  
  47.     # Free the mysqli resources
  48.     @mysqli_free_result($result);
  49.     @mysqli_close($dbLink);
  50.  
  51. }
  52. else
  53. {
  54.     echo "Error! No ID was passed.";
  55. }
  56. ?>

This is the code for get_file.php. When i try to download the file, it says that the errors come from the header part.Hope u can help me.Thank you
Jun 4 '09 #7
ririe
20 New Member
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 37

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs \Inovasi\get_fi le.php:2) in C:\xampp\htdocs \Inovasi\get_fi le.php on line 38
╨╧рб▒с������� ��������� >��■  ������������� ��V����������Y ������■   ���� U���                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ье┴�[А ��°┐������0�� �����╖ ���bjbjм·м·��� ��������� ������ �4R��╬Р�╬Р� ╖������������� ��������������� ��  ���������   ���������  � ��������������� �╖�����

This is the errors come out.I want to view the file first and then the user can download the file.How to do it??
Thank you
Jun 4 '09 #8
Dormilich
8,658 Recognized Expert Moderator Expert
which are those 3 lines?
Jun 4 '09 #9
Markus
6,050 Recognized Expert Expert
@Dormilich
The header() lines in his previous post.

It's strange, though, I don't see any output prior to those calls.

Make sure you have no whitespace before the opening <?php tag.
Jun 4 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

14
9748
by: David W. Fenton | last post by:
I'm no stranger to this error message, but I have a client who is experiencing it, but, fortunately, without any actual data corruption, and it's driving them made. Their inability to grasp that the cause is fundamentally a networking problem is also making me pull my hair out. Some history: The network is composed of five computers dating back to 1995, each purchased one at a time, and each having a different OS, etc. Until
0
5003
by: Rhon Stewart via DotNetMonster.com | last post by:
Hi please visit this link : http://www.eggheadcafe.com/articles/pfc/selfupdater.asp I followed all the steps for listed on the link , when I execute the application it it gives me the following error on the log file: --- ApplicationUpdateManager.StartUpdater] : The Updater has started; the target application's name is 'SayHello'. Time started: 2005_03_01_14:33:21.
3
3869
by: Jocelyn Duhaylungsod | last post by:
I have been getting the following server errors sporadically while downloading excel, csv or xml file. Internet Explorer cannot download <file name> from <IP address> "The server returned an invalid or unrecognized response" / "The connection with the server was reset" I'm using Response.BinaryWrite to send down the file content as attachment (sample codes is attached below). I read some of the similar posts in the newsgroup about the...
3
3987
by: Ramesh Dodamani | last post by:
Environment: XP Pro, VS.Net 2003, .Net 1.1.4322 with SP1 & KB Hotfix 886903 P4 2.2GHz, 1 GB RAM My system was working fine till a few weeks back when I started seeing the following errors. "aspnet_wp.exe (PID: xxxx) stopped unexpectedly" I am seeing the this error currently happen, but unlike the description in articles Q823409 or 821387, I am not downloading any large file .The error
3
2791
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
2
2776
by: Tomas Martinez | last post by:
Hi there! I'm trying to download a file in my asp.net web, but when downloading it from a Firefox browser, instead of downloading the example.exe file, it's downloading example.exe.htm. My code is the following: string localfile = MyComponent.DownloadMyExe(index); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType="application/octet-stream";
0
3714
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
3
2210
by: C. Feldmann | last post by:
Hello, I have stumbled upon a problem, for which I canТt seem to find a solution for. I would like to offer files for downloading. To allow files to have duplicate names I renamed as random alphanumeric- strings. With the header command I can give them their Уold nameФ back just before downloading. Then use readfile or loop through feof/echo fread to push the fileТs contents. This works well. The amount of files has increased, so that...
8
1660
by: JRough | last post by:
What is the purpose of caching in the header below? I used something like this for downloading a detail page to Excel but in this example it looks like it is for cache control? Why would you expire a header? So the user couldn't send a request after too long of a period for example in the downloaded excel page? <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
0
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9873
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectЧplanning, coding, testing, and deploymentЧwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.