LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2004, 12:59 PM   #1
logicdisaster
Member
 
Registered: Jun 2004
Posts: 41

Rep: Reputation: 15
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?
 
Old 10-06-2004, 01:17 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
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.
 
Old 10-06-2004, 01:45 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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>

Last edited by Hko; 10-06-2004 at 01:50 PM.
 
Old 10-07-2004, 01:25 PM   #4
logicdisaster
Member
 
Registered: Jun 2004
Posts: 41

Original Poster
Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php executable binary apt Programming 4 12-08-2004 08:46 AM
PHP Function to return the most recent error. id10t Programming 5 05-30-2004 06:24 PM
php scripts return empty pages ararag Linux - Software 1 02-23-2004 10:46 AM
php mail script return path richard22 Linux - Software 1 08-22-2003 04:10 AM
php - find files (photo*.jpg) and return results to an array omarswan Programming 2 06-20-2003 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration