Diana Castillo [mailto:[EMAIL PROTECTED]] wrote: > > Hi, I want to export some fields on a regular basis from a > table to a text > file, preferable to the users local computer. I tried writing > to a file with > fopen but I get "permission denied" when I try to open it for writing. > What is the best solution? > Thanks, > Diana > It's not clear to me what you want - create a text file on the server, or create a CSV file for download on the fly...
As fopen() tries to create a local file, it seems you (or better, the uid owning the web server process) do not have write permission to where you want to create the file. Your PHP scripts run with the user-id of the web server, which may be www-data, nobody, wwwrun or whatever. You may have to ask the server admin to give that process write permission in your diectory. On the other side it may be better and easier to create a csv file on the fly. Create a page, say csv-export.php, and link to it using a href="csv-export.php/export.csv". This way the user's browser is tricked that the link points to a CSV file, if it does not honor the content-type it sends (see below). In csv-export.php you do <?php Header ("Content-type: text/csv"); ... [insert code here to generate csv data. Just echo() it.] ... And one other thing that caused me headache for at least 4 hours: Your CSV File MUST NOT begin with "ID". Excel (at least '97 and 2000) tries to open that file with the SYLK import filter, which always fails. Put a space in front of ID, and you're safe. Thomas -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php