Writing to a saved file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
falloutx
Forum Newbie
Posts: 3
Joined: Sat Mar 04, 2006 8:04 am

Writing to a saved file

Post by falloutx »

I know is it possible to generate a excel file from a SQL query. But I will like to know if I can use php to query from the database, then write it to a copy of an excel file that is already saved on the server.

I am having trouble figuring out how to create a copy of the saved file on the server.

Any help will be appreciated. Thanks in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

copy()?

I'm going to assume you mean a CSV file. In that case,
fopen('filename', 'at') will allow you to open the file and append to it provided permissions allow it.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I've never worked with excel spreadsheets and php but as far as copying goes have you tried:

http://us2.php.net/manual/en/function.copy.php
falloutx
Forum Newbie
Posts: 3
Joined: Sat Mar 04, 2006 8:04 am

Post by falloutx »

Sorry I did not make myself clear abt the format I was explaining.

I am not using CSV as it does not support many advance functions that I will like to save in the excel template on the server. I am trying to copy a bunch of data into a copied excel template which does chart generation using some macros.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The only Excel format writer doesn't support the chart generation stuff, so it may break. And I don't think the reader is released as yet, or rather stable. The writer is on pear.php.net. The reader is under proposal on pear.php.net
falloutx
Forum Newbie
Posts: 3
Joined: Sat Mar 04, 2006 8:04 am

Post by falloutx »

Thanks for the help...

I am wondering if there is a possibility of downloading a file that is stored on the server without using ftp or any webserver management add on.

I tried the following, but it just creates a new excel file for download and not the data.xls that I have stored in the server.

Code: Select all

# file name for download
  $filename = "data.xls";

  header("Content-Disposition: attachment; filename=\"$filename\"");
  header("Content-Type: application/vnd.ms-excel");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply