Forum Moderators: coopster

Message Too Old, No Replies

Sending PHP output to a file on the server instead of client's browser

..or saving the PHP output file on the client's browser to a file on server

         

funandgames

4:16 am on Jun 12, 2007 (gmt 0)

10+ Year Member



The client fills out a typical HTML form and presses 'submit'. A PHP file is called using the 'action' command and an HTML file is created and displayed on their browser. I need to save that newly created HTML file to my server. Better yet, I would like skip that step and simply have the PHP output go directly to a file on the server instead of the their browser. Can this be done? I am somewhat new to PHP.

Thank you for any help.

mcavic

4:50 am on Jun 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP can write whatever it wants to a file using fopen() and fwrite().

funandgames

5:11 am on Jun 12, 2007 (gmt 0)

10+ Year Member



The PHP file has regular HTML as well as embedded PHP code throughout to generate a web page easily. I need BOTH the embedded HTML and the PHP output to go to the file. If this can be done it would be much easier then rewriting an entire script to create the page piecemeal.

darrenG

10:50 am on Jun 12, 2007 (gmt 0)

10+ Year Member



Yep it can be done.

A couple of points to bear in mind:

- You will need to set the permissions of the destination folder to something like 0757 (that will make sense with a bit of research)

- If you are on a shared server, chmod() which is used to change permissions may be disabled, in which case you must change permissions via an ftp connection dynamically

- dont forget to change permissions back to 0755 or whatever for security reasons

A little bit of googling and looking up chmod, fopen and fwrite and possibly ftp connections in php and you will be well away

coopster

3:09 am on Jun 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like an ideal time to invoke PHP's Output Control Functions [php.net].

funandgames

4:27 am on Jun 13, 2007 (gmt 0)

10+ Year Member



Thank you for the tips. I will try it soon and give an update.

funandgames

1:10 am on Jun 14, 2007 (gmt 0)

10+ Year Member



Coopster,

I would like to sincerely thank you for referring me to that web site. Everything is going exactly as planned on our new site.

Once again WebmasterWorld saves the day!

funandgames

coopster

3:17 am on Jun 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are very welcome.


referring me to that web site
(emphasis added)

That web site is one of your best resources. I use the manual every day. Literally, every day. I also download a local copy of the manual just in case the site is down ;)