Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Holland, Michigan
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    saving query result file to local drive

    I need to save a comma delimited file which contains the results of a Mysql database query to the users local drive. When I try to do the fopen I get "failed to open stream: Permission denied". I am new to PHP and I don't understand what permission I need to set and where. This is an internal intranet running on Linux with Apache. Maybe there is a better way to accomplish this.

  • #2
    4xz
    4xz is offline
    Regular Coder
    Join Date
    Aug 2004
    Location
    localhost
    Posts
    163
    Thanks
    0
    Thanked 1 Time in 1 Post
    U need to set the file- and directorypermissions so that your PHP script can write the file. To do this, go to your shell as root (or another user with enough privileges) and execute command :

    #>chmod 777 <path-to-directory>

    Change the path to directory with the directory where u wanna write the file, for example /var/www/html/datadir.
    Last edited by 4xz; 10-16-2004 at 02:58 AM.

  • #3
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Holland, Michigan
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I probably didn't explain very well what I am trying to accomplish. I want to write the report to the client local drive (c drive on windows xp). The chmod 777 you suggested would be for a path/file on the Linux box which is the server. Maybe I need to write the file to the Linux box first and then access it a different way like FTP. Since PHP is able to write cookies to the client local drive I thought maybe there was a way to write files directly to the local drive. I also wanted to make it easy on the users since they would just want to press a button and get their report from the database query. Any suggestions on the best way to accomplish this would be appreciated. Thanks for the help.

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could set the header of the PHP page to match the file you are downloading mime type and send the data you want.

  • #5
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Holland, Michigan
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry to be so dense but marek_mar could you please explain your post.
    Thanks

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i think there are 2 options:
    - ftp is to the clientmachine (if he allows this)
    - have the browser download it (either initiating an automatic download like marek_mar suggest, or show a downloadlink)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by BettyJ
    Sorry to be so dense but marek_mar could you please explain your post.
    Thanks
    That would be difficult... but if you want to spare me all the explaining it you can read the php manual on the header() function. The last example on that page (not user submited) tels you how to do it with a generated pdf file.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •