User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,444 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,633 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1693 | Replies: 4
Reply
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

php file export issue

  #1  
Nov 5th, 2007
I have a simple php file for example:
<?
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=file123.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "test";
?> 

What I want to do is export php result and save it in excel file. If I run this from web browser like IE,firefox, I have no problem to generate excel file on my local machine.
However I want to run this from command line at background, instead of web browser, now if I open command prompt box and run it, it just print result "test" on command box, there is no export file generated.

Why??? how can I fix this issue?

Any advice will be appreciated.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 81
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: php file export issue

  #2  
Nov 5th, 2007
It looks like your last line is wrong. Also, try this version of the first line. This is what I use:

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print $data;


$data needs to hold the tab delimited text file that you create. Your line just tells the routine to print the string "test". You are not passing any data.

You have to format the data. Separate your fields with chr(9) and end each line with chr(9).
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Re: php file export issue

  #3  
Nov 5th, 2007
Thanks for reply.
I tried this, it works ok from web browser, but not from command line, it doesn't generate excel file.
Actually this $data is the dynamic php web page I created, I want to save this php page into excel file, from command line.
Reply With Quote  
Join Date: Aug 2005
Location: somewhere in time
Posts: 81
Reputation: TopDogger is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
TopDogger's Avatar
TopDogger TopDogger is offline Offline
Junior Poster in Training

Re: php file export issue

  #4  
Nov 5th, 2007
Spreadsheets are for tabular data. How do you plan to break a web page up into cells? Are you talking about data that you are displaying on a PHP page?

I'm not sure how you would do this from a command line.
Reply With Quote  
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Re: php file export issue

  #5  
Nov 6th, 2007
The php page contains table that display dynamic data retrieved from mysql database, I have no problem to display this table on web browser and convert it to excel file, by manually.
Now I need to set cronjob to run this php script at backend to retrieve data from mysql DB and generate excel file in weekly basis, I got stuck here.
Any idea?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 1:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC