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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving a PHP page as a static HTML page

    I work in Dreamweaver 8 and can produce dynamic PHP page with no problem. Now I would like to be able to save these pages as a static HTML page in a folder on the server. My old programmer said this could be done using the fopen command.

    I would like to be able to specify the folder, as well as the file names prefix, the unique id will complete the files name.

    I blend Dreamweaver pages with hardcoded code to get what I need. I just done know where to go from here.

    Any help is appreciated.

  • #2
    Regular Coder Element's Avatar
    Join Date
    Jul 2004
    Location
    Lynnwood, Washington, US
    Posts
    855
    Thanks
    2
    Thanked 2 Times in 2 Posts
    probably something like:


    PHP Code:

    $page 
    file_get_contents($_SERVER['PHP_SELF']);
    $ext "htm";
    $newfilename substr(md5(uniqid()), 08) . "." $ext;
    $path "_tmp/";
    if(
    $handle=fopen($path $newfilename"a+")) {
      if(
    fputs($page$handle)) {
        echo 
    "Static HTML file created.<br><a href=\"http://" $_SERVER['HTTP_HOST'] . "/" $path $newfilename "\" target="_blank">" $newfilename "</a>";
      }

    You can try something like that, edit it around though of course.

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Careful, you might get an infinite loop with that file. Use a dedicated file to open others.

    PHP Code:
    $url $_GET['page'];

    $tmpurl explode("?"basename($url));

    if (
    $tmpurl[0] == $_SERVER['PHP_SELF']) {
         die(
    'Improper page. Cannot open self.');
    }

    $page file_get_contents($url); // Will only work if remote file opens are allowed
    $ext "htm"
    $newfilename substr(md5(uniqid()), 08) . "." $ext
    $path "_tmp/"
    if(
    $handle=fopen($path $newfilename"a+")) { 
      if(
    fputs($page$handle)) { 
        echo 
    "Static HTML file created.<br><a href=\"http://" $_SERVER['HTTP_HOST'] . "/" $path $newfilename "\" target="_blank">" $newfilename "</a>"
      } 

    Last edited by Velox Letum; 01-10-2006 at 12:43 AM.
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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