Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 28-02-06
Barry's Avatar
Typing with both fingers.
 
Join Date: Aug 2003
Location: In Fishguard with my lovely coracle.
Posts: 2,981
Thanks: 114
Thanked 26 Times in 19 Posts
Barry seems to know their stuff
  Force download of dynamically created content.

I want to make a site that enables people to download xml files by pressing on a link to them, but at the moment the xml files just open in a browser window.

I have been trying to do this via php and here is the code I have so far but I can't seem to get it to work. Are there any php gurus out there that can tell me where I am going wrong with it

PHP Code:
// load content into var
$filecontent $row_rs_xmlfile['xmlcontent'];
//name the file
$downloadfile $row_rs_xmlfile['xmlurl'];

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Description: File Transfer'); 
header("Content-Type: application/force-download");
header("Content-disposition: attachment; filename=$downloadfile");
header("Content-Transfer-Encoding: Binary");
header("Content-Length: ".strlen($filecontent));
header("Pragma: no-cache");
header("Expires: 0");
exit(); 
Ta
__________________
Mirror Ten Ltd :: Free Codes :: HTC Touch HD
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-02-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
Hi Barry,

This is what I use - (in 2 separate apps)

PHP Code:
  $filename "foo.xml";
  
header('Cache-Control: no-store, no-cache, must-revalidate, private, post-check=0, pre-check=0'FALSE);
  
header('Pragma: no-cache');
  
header("Content-Type: application/octet-stream");
  
header("Content-Disposition: attachment; filename=$filename"); 
Looks pretty much the same though; but if definitely provokes the "Save As" dialog box in all current browsers...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-03-06
Barry's Avatar
Typing with both fingers.
 
Join Date: Aug 2003
Location: In Fishguard with my lovely coracle.
Posts: 2,981
Thanks: 114
Thanked 26 Times in 19 Posts
Barry seems to know their stuff
Nice one mate I will give that a go now and let you know how I get on. However idealy I wanted the download file contents to be created dynamically from the database on the fly rather than having to create a file first for download.

Does anybody have any recommendation for doing it that way? Or is the only way to create a file on the fly and then send it to the listed download script?
__________________
Mirror Ten Ltd :: Free Codes :: HTC Touch HD
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-03-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
There's no problem doing that Barry - in fact, that's what I do - the $filename = "foo.xml" was just for example.

PHP Code:
header('Cache-Control: no-store, no-cache, must-revalidate, private, post-check=0, pre-check=0'FALSE);
header('Pragma: no-cache');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=somefilename.xml"); 

// dynamically generate and output content here 
Now, if you want the users' browser to display a progress bar (in which case it needs to know the content length); you could generate the content into a temporary variable before generating the headers, and include the content-length as per your original code:

PHP Code:
// dynamically generate $xml:
$xml "<foo><bar>widget</bar></foo>";

header('Cache-Control: no-store, no-cache, must-revalidate, private, post-check=0, pre-check=0'FALSE);
header('Pragma: no-cache');
header("Content-Type: application/octet-stream");
header("Content-Length: ".strlen($xml)); 
header("Content-Disposition: attachment; filename=somefilename.xml"); 

print 
$xml
Should do the trick...

Last edited by dmorison; 01-03-06 at 12:22 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 01-03-06
Barry's Avatar
Typing with both fingers.
 
Join Date: Aug 2003
Location: In Fishguard with my lovely coracle.
Posts: 2,981
Thanks: 114
Thanked 26 Times in 19 Posts
Barry seems to know their stuff
  Thumbs up

Thanks soooooo much!!! Sometimes I can bang my head against a wall for hours - then come to this forum and get an answer in minutes.

Thanks again thats cool and works for me

__________________
Mirror Ten Ltd :: Free Codes :: HTC Touch HD
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Content really will be king - your thoughts? Malcolm Cowley The Affiliate Marketing Lounge 16 25-07-05 01:34 PM
Advanced Content Units - Sneak Preview paidonresults Paid On Results 6 16-05-05 07:25 PM
If you use flash, quicktime or avis on your website - read this drivetowin The Affiliate Marketing Lounge 0 08-11-03 06:00 PM
ShopWindow Custom Content Marc Gear Affiliate Window 5 10-10-03 02:47 PM
Introducing DGM2 content units tonystubbings DGM Affiliates 11 23-01-03 02:08 AM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7