PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 24th, 2004, 05:12 AM
zalfreid zalfreid is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 zalfreid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question PHP: download PHP generated files

I have such a problem in my project.
PHP generates table and i have to save this table on user's machine in some type
for example CSV. How it is possible to do in PHP to generate file and make it possible to
download like usual file from url without using server's space.

Thanx in advance

Reply With Quote
  #2  
Old May 27th, 2004, 05:08 PM
dotty dotty is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 7 dotty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Below is the code I use to print onto a page which can be downloaded as csv file.

Make a new page called 'anythingyoulike.php'. Substitute your connection,recordset, fieldnames for your own. Make sure that your client knows that when saving to his/her computer, select 'text file' as the filetype option and not html - also name the file with extension .csv

PHP Code:
<?php require_once('connection.php'); ?>
<?php
mysql_select_db
($database_bbcomp$bbcomp);
$query_export_file "SELECT * FROM bbcomp WHERE maillist = 'Y'";
$export_file mysql_query($query_export_file$bbcomp) or die(mysql_error());
$row_export_file mysql_fetch_assoc($export_file);
$totalRows_export_file mysql_num_rows($export_file);
/*echo "ID".","."First Name".","."Last Name".","."Address1".","."Address2".","."Country".","."Telephone".","."Mobile".","."Email".","."Age".","."Sex".","."Question".","."Interests".","."Opt-in Maillist"."<br><br>";*/
do {
echo 
$row_export_file['id'].",".$row_export_file['firstname'].",".$row_export_file['lastname'].",".$row_export_file['address1'].",".$row_export_file['address2'].",".$row_export_file['county'].",".$row_export_file['phone'].",".$row_export_file['mobile'].",".$row_export_file['email'].".".$row_export_file['age'].",".$row_export_file['sex'].",".$row_export_file['question'].",".$row_export_file['interests'].",".$row_export_file['maillist']."\n";
} while (
$row_export_file mysql_fetch_assoc($export_file));
 
?>

Zalfreid - did you discover a way to save directly to computer? If so, would you share it here?

Hope this helps you.

Reply With Quote
  #3  
Old June 5th, 2004, 11:45 AM
Archemides Archemides is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 25 Archemides User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archemides Send a message via AIM to Archemides Send a message via Yahoo to Archemides
Dummy Zip Files download ok.

I wanted to find a way to create a zip or tar file at my site, with php, so that someone might download it, but i could not use exec(tar..) or system(tar...) because my host does not give me access, but I found a neat trick... if i rename any file as somefile.zip , then it automatically downloads, even though it is not a zip file


The user can click on a link to that dummy.zip file, or simply point their browser to http://somesite.com/dummy.zip , and it downloads

Reply With Quote
  #4  
Old June 5th, 2004, 11:57 AM
Archemides Archemides is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 25 Archemides User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Archemides Send a message via AIM to Archemides Send a message via Yahoo to Archemides
Different approach

Someone in IRC #phpfreaks channel just kindly gave me this link, though I have not tried it out.

http://www.sephiroth.it/phpwiki/ind...%20text%20files
Description:
When you need to send to the browser a 'text' (or .as, .sql, or php file too) base file but you don't want that the browser displays it in the output. If you want to allow browser ask to "save" the document use this php header (seems working also under netscape)

the code:
PHP Code:
<?
   $string 
"bla bla bla";  // this can be a variable string or a row from a sql query or something else...
   
$ext "txt";   // file extension
   
$mime_type = (PMA_USR_BROWSER_AGENT == 'IE' || PMA_USR_BROWSER_AGENT == 'OPERA')
   ? 
'application/octetstream'
   
'application/octet-stream';
   
header('Content-Type: ' $mime_type);
   if (
PMA_USR_BROWSER_AGENT == 'IE')
   {
      
header('Content-Disposition: inline; filename="' $filename '.' $ext '"');
      
header("Content-Transfer-Encoding: binary");
      
header('Expires: 0');
      
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      
header('Pragma: public');
      print 
$string;
   } else {
      
header('Content-Disposition: attachment; filename="' $filename '.' $ext '"');
      
header("Content-Transfer-Encoding: binary");
      
header('Expires: 0');
      
header('Pragma: no-cache');
      print 
$string;
   }
?>

Last edited by edwinbrains : June 6th, 2004 at 01:18 PM. Reason: [php] and [/php] added

Reply With Quote
  #5  
Old June 6th, 2004, 01:19 PM
edwinbrains's Avatar
edwinbrains edwinbrains is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: UK
Posts: 160 edwinbrains User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 5 m 50 sec
Reputation Power: 5
Archemides: I added [php ] and [/php ] tags to that, just to make it easier to read.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP: download PHP generated files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT