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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post

    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?

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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); 

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

  • #4
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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

  • #5
    New Coder
    Join Date
    Oct 2007
    Posts
    84
    Thanks
    0
    Thanked 8 Times in 8 Posts
    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.

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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!');

  • #7
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    ok it's writing the file perfectly, however the page no longer loads. it's just a blank white screen.

  • #8
    New Coder
    Join Date
    Oct 2007
    Posts
    84
    Thanks
    0
    Thanked 8 Times in 8 Posts
    PHP Code:
    print $return

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    No, print $content; or change ob_get_clean() to ob_get_flush().

  • #10
    New Coder
    Join Date
    Oct 2007
    Posts
    84
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Oops

    I had just woken up and picked the first variable I saw

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

  • #12
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    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.

  • #13
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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?

  • #14
    New Coder
    Join Date
    Oct 2007
    Posts
    59
    Thanks
    9
    Thanked 1 Time in 1 Post
    no errors are getting displayed. the variable $uic is declared

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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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