Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2007, 09:30 PM   PM User | #1
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
Saving a webpage to the webserver

Ok i have a page thats generated after a form is submitted. What code can i use to save a copy of that page to a folder on my webserver?
Doom87 is offline   Reply With Quote
Old 11-05-2007, 11:54 PM   PM User | #2
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
PHP Code:
$contents file_get_contents("http://...");
$file_to_save "text.txt";

$file_opened fopen($file_to_save'a+');
fputs($fi_opened$contents);
fclose($file_opened); 
matak is offline   Reply With Quote
Old 11-06-2007, 01:15 AM   PM User | #3
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
Ok it saved a file named text.txt but there is no info in the document. Also the page generated this error message:


Warning: file_get_contents(http://www.domain.com/engr/servlet/s...092&num5=84117) [function.file-get-contents]: failed to open stream: HTTP request failed! in /home/ootaclan/public_html/engr/servlet/scripts/printouts/newuser/printout.php on line 79
Doom87 is offline   Reply With Quote
Old 11-06-2007, 01:26 AM   PM User | #4
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
It requires some kind of trigger to be set on your localhost when page is submited. If that was on the same server it wouldn't be problem (i guess), but sending HTTP request to far away server and dynamicly uploading it is possible only with Ajax, or some super cool cgi or similar script which i would really like to see if anyone is following me, please answer what could it be possible to use instead of lousy javascript
matak is offline   Reply With Quote
Old 11-06-2007, 02:12 AM   PM User | #5
toddandrae
New Coder

 
Join Date: Oct 2007
Posts: 84
Thanks: 0
Thanked 8 Times in 8 Posts
toddandrae is an unknown quantity at this point
You could always

PHP Code:
$content "";
$content .="<html>";
$content .="<head>";
... 
And then use fopen and write that output to a file and then print that output to the screen. You could also use ob_start and ob_get_flush.
toddandrae is offline   Reply With Quote
Old 11-06-2007, 03:52 AM   PM User | #6
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
PHP Code:
<?php
ob_start
();

// put your page here

$content ob_get_clean();

$return file_put_contents('text.txt'$content); // or change to file_put_contents('text.txt', $content, FILE_APPEND); if you want to append the file

if($return == false)
    die(
'Failed to write file!');
Inigoesdr is offline   Reply With Quote
Old 11-06-2007, 05:00 AM   PM User | #7
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
ok it's writing the file perfectly, however the page no longer loads. it's just a blank white screen.
Doom87 is offline   Reply With Quote
Old 11-06-2007, 12:17 PM   PM User | #8
toddandrae
New Coder

 
Join Date: Oct 2007
Posts: 84
Thanks: 0
Thanked 8 Times in 8 Posts
toddandrae is an unknown quantity at this point
PHP Code:
print $return
toddandrae is offline   Reply With Quote
Old 11-06-2007, 03:36 PM   PM User | #9
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
No, print $content; or change ob_get_clean() to ob_get_flush().
Inigoesdr is offline   Reply With Quote
Old 11-06-2007, 04:21 PM   PM User | #10
toddandrae
New Coder

 
Join Date: Oct 2007
Posts: 84
Thanks: 0
Thanked 8 Times in 8 Posts
toddandrae is an unknown quantity at this point
Oops

I had just woken up and picked the first variable I saw
toddandrae is offline   Reply With Quote
Old 11-06-2007, 04:30 PM   PM User | #11
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
Ok i have it saving and loading properly. I tried to change the name of the file it saves but couldn't get it to work. I'm trying to set it equal to a variable.

Here's what i tried:
PHP Code:
$file_to_save "../../../archives/docs/account_details/$uic.txt"
also tried:
PHP Code:
$file_to_save "../../../archives/docs/account_details/" $uic ".txt"
both yield no file saved.
Doom87 is offline   Reply With Quote
Old 11-06-2007, 05:17 PM   PM User | #12
matak
Banned

 
Join Date: Apr 2007
Posts: 428
Thanks: 29
Thanked 5 Times in 5 Posts
matak is on a distinguished road
it will not save in file with file_put_contents if file doesn't egzist.
you need to use fopen with 'a+', then file will be created it doesn't egzist.

Edit: this is not correct, like aerdin wrote in post below. sorry and thanks.

Last edited by matak; 11-06-2007 at 08:28 PM..
matak is offline   Reply With Quote
Old 11-06-2007, 06:11 PM   PM User | #13
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
Quote:
it will not save in file with file_put_contents if file doesn't egzist.
This is wrong. The whole purpose of file_put_contents() is to have an easy method of writing to a text file without the worry of modes/existing files/etc.

Are you displaying errors? Are you sure the $uic variable contains a value?
aedrin is offline   Reply With Quote
Old 11-06-2007, 10:29 PM   PM User | #14
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
no errors are getting displayed. the variable $uic is declared
Doom87 is offline   Reply With Quote
Old 11-07-2007, 12:03 AM   PM User | #15
Doom87
New Coder

 
Join Date: Oct 2007
Posts: 59
Thanks: 9
Thanked 1 Time in 1 Post
Doom87 is an unknown quantity at this point
yep just double checked by doing an echo $uic; it shows up with the correct info. just the file ain't saving anymore

just wondering if this could be it: Is there a max length for the name of a saved file. Because the variable $uic stands for user identification code which is a 25 digit number.

Edit: Apparantly not because i just tried it with a shorter variable length and still got no file saved

Last edited by Doom87; 11-07-2007 at 12:10 AM..
Doom87 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:15 AM.


Advertisement
Log in to turn off these ads.