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 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post

    Saving a Web Page with PHP

    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

  • #2
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Instead of adding a string just point it to whereever the webpage is located.

    PHP Code:
    //fopen wrappers have to be enabled
    file_put_contents("path/to/save.txt""http://www.example.com"); 
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • Users who have thanked StupidRalph for this post:

    Doom87 (03-09-2008)

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    Ok i'll try that out

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You probably want something like this:
    PHP Code:
    $webpage file_get_contents('http://urltoget.com/');
    // add error checking
    file_put_contents($lastname '.txt'$webpage); 
    See the manual pages for more info and examples.

  • Users who have thanked Inigoesdr for this post:

    Doom87 (03-09-2008)

  • #5
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    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

  • #6
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    i'll try out ur suggesstion Inigoesdr

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by Doom87 View Post
    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).

  • Users who have thanked Inigoesdr for this post:

    Doom87 (03-09-2008)

  • #8
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    Ya I got it working now, Thanks for all the help guys!

  • #9
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    I'm sorry I should've tried it out first....don't know didn't use file get contents to retrieve the webpage.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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