Viewed   105 times

What approach could someone suggest to save the current page as an HTML file to the server? In this case, also note that security is not an issue.

I have spent endless hours searching around for this, and have not found a single thing.

Your help is much appreciated, thank you!

Edit

Thank you all for your help, it was very much appreciated.

 Answers

4

If you meant saving the output of a page in a file, you can use buffering to do that. The function you need to use are ob_start and ob_get_contents.

<?php
// Start the buffering //
ob_start();
?>
Your page content bla bla bla bla ...

<?php
echo '1';

// Get the content that is in the buffer and put it in your file //
file_put_contents('yourpage.html', ob_get_contents());
?>

This will save the content of the page in the file yourpage.html.

Monday, August 22, 2022
2

Most like this is a permissions issue. I'm going to assume you don't have any kind of direct shell access to check this stuff directly, so here's how to do it from within the script:

Check if the $target directory exists:

$target = '/data/etc....';
if (!is_dir($target)) {
    die("Directory $target is not a directory");
}

Check if it's writeable:

if (!is_writable($target)) {
    die("Directory $target is not writeable");
}

Check if the full target filename exists/is writable - maybe it exists but can't be overwritten:

 $target = $target . basename($_FILES['image']['name']);
 if (!is_writeable($target)) {
     die("File $target isn't writeable");
 }

Beyond that:

if(!(move_uploaded_file($_FILES['image']['tmp_name'], $target))) {
    echo $_FILES['image']['error']."<br />";
}

Echoing out the error parameter here is of no use, it refers purely to the upload process. If the file was uploaded correctly, but could not be moved, this will still only echo out a 0 (e.g. the UPLOAD_ERR_OK constant). The proper way of checking for errors goes something like this:

if ($_FILES['images']['error'] === UPLOAD_ERR_OK) {
    // file was properly uploaded
    if (!is_uploaded_File(...)) {
        die("Something done goofed - not uploaded file");
    }
    if (!move_uploaded_file(...)) {
        echo "Couldn't move file, possible diagnostic information:"
        print_r(error_get_last());
        die();

    }
} else {
    die("Upload failed with error {$_FILES['images']['error']}");
}
Saturday, September 17, 2022
 
cambium
 
2

Try something like this:

// Start output buffering
ob_start();
// run code in x.php file
// ...
// saving captured output to file
file_put_contents('filename.htm', ob_get_contents());
// end buffering and displaying page
ob_end_flush();

If you cannot use the ob_* functions, you can also write the form to a variable and then save that variable.

Tuesday, August 23, 2022
4

Via JavaScript Strictly, No.

But here are two alternatives, 1 client side and 1 server side.

Force Download via HTM5 link.

Now the HTML5 spec defines a very useful download attribute on hyperlinks that basically allows to force download behavior on client-side, regardless of what comes in Content-Type and Content-Disposition from the server.

Fiddled Here: http://jsfiddle.net/qmwxt/

<a href="URL" download> Download your Question</a>

Read more here: https://.com/a/15970140/144665

Set Content-Disposition in the header.

Or if you have server side control set Content-Disposition in the header which forces the save dialog.

Read more here: How to encode the filename parameter of Content-Disposition header in HTTP?

Saturday, August 13, 2022
 
keyser
 
5

Are your non-EPiServer pages just custom aspx pages? If this is the case you have problems with you can check if the current page inherits from an EPiServer page by checking the Page's type. I believe all EPiServer pages inherit from PageBase.

if (Page is EPiServer.PageBase) {...}
Monday, September 12, 2022
 
z80
 
z80
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :