Jump to content

File Adds Html?


kirbyweb

Recommended Posts

I have a page where you can download files from your db, but it includes the html on the page to the file does anyone know why? here is the code:

<table><tr><td><form method="POST">Full Name:</td><td><input type="text" name="name" /><br /></td></tr><tr><td>File Name:</td><td><input type="text" name="file_name" /><br /></td></tr><tr><td><input type="submit" name="submit" value="submit" /></form></td></tr></table><?php$name = $_POST['name'];$file_name = $_POST['file_name'];$submit = $_POST['submit'];if ($submit){$connect  $sql = mysql_query("SELECT file_itself, file_type, file_name, file_size FROM `form_files_info` WHERE full_name = '$name' && file_name = '$file_name'");  $count = mysql_num_rows($sql);  if ($count == 0)  {   die('No Name or File Name named that.');  }else  $data = mysql_result($sql, 0, "file_itself");  $name = mysql_result($sql, 0, "file_name");  $size = mysql_result($sql, 0, "file_size");  $type = mysql_result($sql, 0, "file_type");	  header("Content-type: $type");  header("Content-length: $size");  header("Content-Disposition: attachment; filename=$name");  header("Content-Description: PHP Generated Data");  echo $data;}?>

Please help thanks.

Link to comment
Share on other sites

Because you're trying to send a bunch of headers and binary data in the middle of an HTML page. Binary file data doesn't include a bunch of HTML tags around it. If you're sending HTML then send HTML, if you're sending a file then send a file. You can't do both at the same time.

Link to comment
Share on other sites

The part which outputs the file data needs to be its own file, you can't start outputting a binary stream in the middle of an HTML document. You need a link or something else to run your download page, and the only thing it does is look up the file in the database, send the headers, and send the file data.

Link to comment
Share on other sites

You wouldn't be able to put it on the same page, but you can format the page if you detect the error instead of just printing the text and exiting. You could also check that the ID exists in the database prior to showing the link.

Link to comment
Share on other sites

You can't make text appear on the page where the link is, that's what I said. You can either show just the error, or set up a formatted HTML page and put the error on it, or check for the error before you even show the link in the first place.

Link to comment
Share on other sites

This is the third time, so hopefully it sinks in: you can't have one page update another arbitrary page in real time. You just can't. It doesn't matter what the situation is, that's not how HTTP works. The only thing you can do is have Javascript code that will take the error message and call a function on the parent page to send it the error, and the parent page can do whatever it wants with the message. Using window.opener will refer to the page which opened the current page, if you have a function defined on that page called do_error then you can call it from the popup using window.opener.do_error, and you can send your error message to have it update the page.

Link to comment
Share on other sites

This is the third time, so hopefully it sinks in: you can't have one page update another arbitrary page in real time. You just can't. It doesn't matter what the situation is, that's not how HTTP works. The only thing you can do is have Javascript code that will take the error message and call a function on the parent page to send it the error, and the parent page can do whatever it wants with the message. Using window.opener will refer to the page which opened the current page, if you have a function defined on that page called do_error then you can call it from the popup using window.opener.do_error, and you can send your error message to have it update the page.
I already did it in php, you just put the html on top of the php code, so you can.
Link to comment
Share on other sites

I think we're talking about 2 different things. From my understanding you have a page pop up to download the file, and if there was an error instead of showing the error on that popup you wanted to show it on the parent page. If that's not your situation then I misunderstood.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...