Jump to content


Photo

output string as file


  • Please log in to reply
4 replies to this topic

#1 3rve

3rve
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 June 2006 - 08:27 PM

I am trying to send the contents of a string to the browser as a file, Is there a way to do this without actually creating a file and then sending it back. I don't have any code to share on this , as I have no clue if it is possible, thanks

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 June 2006 - 08:33 PM

You can pass string data using the $_GET array by attaching the string to the URL; or by using the $_POST (or $_GET) array via a form submission using the post (or get) method; or by setting the string as a session value and recovering it in the next script; or by creating a cookie containing the string and recovering it in the next script.

Does any of that have anything to do with what you're hoping to do?
Legend has it that reading the manual never killed anyone.
My site

#3 3rve

3rve
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 June 2006 - 09:25 PM

No not really. Maybe I can clarify what I meant. I have a page where a user submits data into a textarea. I take that input and apply some regular expressions to it so that i can extract certain information. I then want to take the information that I am extracting and create an xml file from that. I have the code already built where php fills in all the blanks between my elements and sends it to the broswers as a regular php/html file. If you view the page source of the php output in the web browser you can see all the xml elements. I just want to take those elements into a file , xml, and when the script is used you are prompted for an xml file download or you are passed a xml file not a php file. I also don't want to create any files on the server, if I wanted to do that I would not be asking for help since that i do know how to do!. Thanks

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 June 2006 - 09:44 PM

Guess my crystal ball wasn't working too well when I responded first.

I can't help you with that, but now that you've explained what it is you're trying to do maybe someone else will be able to help you.
Legend has it that reading the manual never killed anyone.
My site

#5 3rve

3rve
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 June 2006 - 12:49 AM

Found the answer to my own question. Thanks to all who looked.

header('Content-type: application/xml'); <- insert whatever application type you are trying to send
header('Content-Disposition: attachment; filename="download.xml"'); <- filename = whatever you want

any content that your script would send to the browser after the header will be sent to the browser as a file to be downloaded.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users