Click to See Complete Forum and Search --> : [RESOLVED] automated php to html
LingoOutsider
Jun 5th, 2009, 08:07 AM
I'm using php to to pull information from a database and place it on a template. I now want to archive the template(s) in html.
I can do this by viewing them in a browser and saving them as html then upload them onto my webspace or email them.
Is there a faster way of doing this?
send page by email?how?
kows
Jun 5th, 2009, 01:29 PM
well, if you have a template file that is formatted so that you can replace things easily (replacing all iterations of "##TITLE##" in a template with the actual title, etc), then you can load it all into a variable and just save the file.
but, if you're not using a template like that, you could just turn on output buffering (http://ca2.php.net/manual/en/function.ob-start.php) so that when you're all finished processing the page, you can store it all in a variable and then save it.
if you'd like to automate everything, you can then try using the ftp_* functions (http://ca2.php.net/manual/en/book.ftp.php) to upload the file to your web server.
LingoOutsider
Jun 8th, 2009, 03:14 AM
If I use an ftp function to save the file to a server can I then send that file as an email?
LingoOutsider
Jun 8th, 2009, 04:18 AM
$conn = ftp_connect("ftp.testftp.com") or die("Could not connect");
ftp_login($conn,"admin","pass");
$source=form.php;
$date=date("d/m/y");
echo ftp_fput($conn,"$date.html",$source,FTP_ASCII);
ftp_close($conn);
Can i use ftp_fput() to save the file?
This looks to connect OK but no file is created. Have I used the $source in the correct way?
There are alot of guides/commands for saving .txt files but not a .php.
kows
Jun 8th, 2009, 05:03 AM
form.php would need to be surrounded by quotes, but yes -- basically. ftp_fput() is also only used to upload open files. otherwise, you want to use ftp_put() (http://ca.php.net/manual/en/function.ftp-put.php) instead. remember that a file with a PHP extension is just a renamed TXT file. they're both plain text files and are really not different at all.
and yes, you can send a file later on as an attachment. you can use the mail() (http://ca.php.net/manual/en/function.mail.php) function to do this, plus add an attachment by adding your own headers. you can look through the many examples in the comments for the mail() function, or more specifically, this one (http://ca.php.net/manual/en/function.mail.php#50530) might be of some help.
LingoOutsider
Jun 8th, 2009, 08:33 AM
So I've put this code at the bottom of my PHP page...
$conn = ftp_connect("x.x.x.x") or die("Could not connect");
ftp_login($conn,"user","pass");
$source="Form.php"; // the page currently being viewed
$date=date("d/m/y"); // name of new file
echo ftp_put($conn,"$date.html",$source,FTP_ASCII);
ftp_close($conn);
I don't get an error connection ("Could not connect") windows firewall asked if its OK to send I said yes, Is there any reason It's not appering on the server? or is there a process of testing?
kows
Jun 8th, 2009, 01:04 PM
use something like this instead:
<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// close the FTP stream
ftp_close($conn_id);
?>
LingoOutsider
Jun 11th, 2009, 01:47 AM
Can I send the file as an email? from the server?
kows
Jun 11th, 2009, 06:03 AM
yes. read more on the bottom lines of this (http://www.vbforums.com/showpost.php?p=3534442&postcount=5) post.
LingoOutsider
Jun 18th, 2009, 07:12 AM
Thanks I'm sorted now.
SambaNeko (from XML, HTML, Javascript, Web and CSS) gave me this...
$to = "email@example.com";
$subject = "This awesome website";
$message = file_get_contents('http://www.example.com');
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.