...

View Full Version : Saving a Web Page with PHP



Doom87
03-09-2008, 09:08 PM
Hello I was hoping somebody could tell me how i can use the file_put_contents to save an entire web page to a file called $lastName.txt

I've googled for some tutorials and such but all i could find is this: echo file_put_contents("test.txt","Hello World. Testing!");

which only saves a string, not the whole page.

Thanks in Advanced

StupidRalph
03-09-2008, 09:37 PM
Instead of adding a string just point it to whereever the webpage is located.



//fopen wrappers have to be enabled
file_put_contents("path/to/save.txt", "http://www.example.com");

Doom87
03-09-2008, 09:45 PM
Ok i'll try that out

Inigoesdr
03-09-2008, 09:46 PM
You probably want something like this:

$webpage = file_get_contents('http://urltoget.com/');
// add error checking
file_put_contents($lastname '.txt', $webpage);
See the manual (http://php.net/file_get_contents) pages (http://php.net/file_put_contents) for more info and examples.

Doom87
03-09-2008, 09:47 PM
I got an error and i'm not sure how to correct it:

Warning: file_put_contents(/applications/asdf.txt) [function.file-put-contents]: failed to open stream: No such file or directory in /home/ootaclan/public_html/Brent_Industries/employee_application.php on line 525

Doom87
03-09-2008, 09:48 PM
i'll try out ur suggesstion Inigoesdr

Inigoesdr
03-09-2008, 10:04 PM
I got an error and i'm not sure how to correct it:

Warning: file_put_contents(/applications/asdf.txt) [function.file-put-contents]: failed to open stream: No such file or directory in /home/ootaclan/public_html/Brent_Industries/employee_application.php on line 525

Your path is wrong. If you start with a forwardslash the system looks for the directory starting with the root(where home is).

Doom87
03-09-2008, 10:06 PM
Ya I got it working now, Thanks for all the help guys!

StupidRalph
03-09-2008, 10:57 PM
I'm sorry I should've tried it out first....don't know didn't use file get contents to retrieve the webpage.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum