|
-
Jun 5th, 2009, 08:07 AM
#1
Thread Starter
Addicted Member
[RESOLVED] automated php to html
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?
Last edited by LingoOutsider; Jun 5th, 2009 at 08:32 AM.
-
Jun 5th, 2009, 01:29 PM
#2
Re: automated php to html
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 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 to upload the file to your web server.
-
Jun 8th, 2009, 03:14 AM
#3
Thread Starter
Addicted Member
Re: automated php to html
If I use an ftp function to save the file to a server can I then send that file as an email?
-
Jun 8th, 2009, 04:18 AM
#4
Thread Starter
Addicted Member
Re: automated php to html
PHP Code:
$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.
-
Jun 8th, 2009, 05:03 AM
#5
Re: automated php to html
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() 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() 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 might be of some help.
-
Jun 8th, 2009, 08:33 AM
#6
Thread Starter
Addicted Member
Re: automated php to html
So I've put this code at the bottom of my PHP page...
PHP Code:
$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?
-
Jun 8th, 2009, 01:04 PM
#7
Re: automated php to html
use something like this instead:
PHP Code:
<?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); ?>
-
Jun 11th, 2009, 01:47 AM
#8
Thread Starter
Addicted Member
Re: automated php to html
Can I send the file as an email? from the server?
-
Jun 11th, 2009, 06:03 AM
#9
Re: automated php to html
yes. read more on the bottom lines of this post.
-
Jun 18th, 2009, 07:12 AM
#10
Thread Starter
Addicted Member
Re: automated php to html
Thanks I'm sorted now.
SambaNeko (from XML, HTML, Javascript, Web and CSS) gave me this...
PHP Code:
$to = "[email protected]"; $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);
Last edited by LingoOutsider; Jun 18th, 2009 at 07:16 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|