LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Php to return a binary not html (https://www.linuxquestions.org/questions/programming-9/php-to-return-a-binary-not-html-239464/)

logicdisaster 10-06-2004 12:59 PM

Php to return a binary not html
 
Im writing a script that when contacted dynamically reads in certain files and returns the text on the screen as html but i also need to have the option that if someone contacts the server with the url string binary=true then the php script should read those file and return them as a binary(download) . Any one know how i can do this?

deiussum 10-06-2004 01:17 PM

I've done something like this to create images that are created "on the fly" by using something like:

header("Content-type: image/jpeg");

That lets the browser know that you are returning a type other than text/html so that it can handle it appropriately. You can then just print out the binary you need.

Hko 10-06-2004 01:45 PM

Code:

<?php
//
// Note this PHP part must be put before any output!
// (read about this in the manual of header()  )
//
  if ($_GET['binary'] == "true") {
      header("Location: http://$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URL]/~Hko/yourfile.bin");
      exit;
  }
?>

<html><head>
<title>Download binary</title>
</head><body>


<h1>No download was requested<h1>
</body></html>


logicdisaster 10-07-2004 01:25 PM

cool the changing the content type was what i was trying to do the only problem with that is that it returns the file as index.php, although hko your idea is probably pretty good to i could create a temporary file and then forward them to that, just not sure it will work with the client (its a game running on cellphone) thanks guys


All times are GMT -5. The time now is 09:39 AM.