tuddy 0 Report post Posted August 9, 2005 Is there a way to have PHP read a text file, which contains HTML Code, not text to display. This way i have a simple code in every page, linking to this text file, and then if i'm wanting to change the code, i only need to change the code in the text file. If that all makes sense? I get the feeling it can be done, but the only code i have seen is one that displays the contents of the text files. Share this post Link to post Share on other sites
Tyssen 0 Report post Posted August 9, 2005 You can use PHP includes. Place this wherever you want your file to appear: <?php include ("$path/yourfile.inc"); ?>.inc is the suffix for include, but you can include any sort of file: .htm, .php, .txt etc. You can put whatever you want in your include. Place the link to the include on multiple pages, then when you want to update them all, you just update one file. Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 9, 2005 Thanks..Great help.Will it work with .doc .xml .rtf ?? I'm guessing not through mmm...Thanks again! Share this post Link to post Share on other sites
Tyssen 0 Report post Posted August 9, 2005 Will it work with .doc .xml .rtf ?? I'm guessing not through mmm...Thanks again!It probably still will but because .doc and .rtf are made up of formatting information that you don't see on screen when you view the document, that stuff will end up in your page as gobbledegook. Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 9, 2005 WooHoo...I got it to work just fine, thank you so much.Now for my next question, here is what i got. i got one page that calls up the form, then another that calls the php file that has the script. Is there a way i can mail the called file with the data inserted into it?Take alook HERE to understand more ..Just enter some random stuff! Share this post Link to post Share on other sites
Tyssen 0 Report post Posted August 10, 2005 Your link doesn't work, but I think you're talking about emailing the contents of a form filled out by a user. You can definitely do that, but as I'm more familiar with ASP than PHP, I wouldn't really be able to help you out. There are two ways of doing it though: processing the form with another PHP file or processing it with the same file as contains the form. The latter method is called a self-referencing form and is good for recording and printing errors to the screen before the form data is submitted.Just do a search on 'php form email' in Google and you'll come up with lots of info. Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 10, 2005 Thanks, it work alittle, but not properly. so i have thought of another way to do it.All this will be done by the one form processer (PHP Page)1) Open the text file. (This text file contains HTML Code with 'placeholders for where the form data will be submitted in place of.)2) Write the form data to the text file, replacing only the placeholders.3) Then save it as a new file, but changing it to (something.html) everytime, to the server.4) Then have a Email send the 'new' file as an attachment.5) Then delete the 'new' file from the server ready for the next form to be submitted.Opening the file i can do.Replacing placeholders i can have a crack at.but i get stuck again with, How do i save it as a new file, and change the file type? Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 10, 2005 Oh and i forgot, thanks Tyssen, your helpwas great, helped me with displaying the form back to the user after they submitted it. and sorry the link didn't work, i just looked at the link and i out .htm instead of .php which it is. sorry! Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 13, 2005 (edited) I have the following code now, $file2 = 'files/leave1.txt'; $file3 = 'files/leave1.htm'; copy ($file1, $file2); $from=array(); $from[]="<<number>>"; $from[]="<<rank>>"; $from[]="<<initials>>"; $from[]="<<family>>"; $from[]="<<datef>>"; $from[]="<<datet>>"; $from[]="<<dates>>"; //and so on to have all the fields you want to replace $to=array(); $to[]=$number; $to[]=$rank; $to[]=$initials; $to[]=$family; $to[]=$datef; $to[]=$datet; $to[]=$dates; //And so on to have all the strings you have to put in place of the fields $string=str_replace($from,$to,$string); $fp = fopen( "$file2" , "w" ); fputs( $fp, $string ); fclose( $fp ); copy ($file2, $file3); $fileatt = "files/leave1.htm"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "leave1.htm"; // Filename that will be used for the file as the attachment $email_from = "Test"; // Who the email is from $email_subject = "Leave Application"; // The Subject of the email $email_message = "This is a Leave Application."; // Message that the email has in it $email_to = "cm44750@cadetnet.gov.au"; // Who the email is too $headers = "From linenums:0'><?php $file1 = 'files/leave.txt';$file2 = 'files/leave1.txt';$file3 = 'files/leave1.htm';copy ($file1, $file2);$from=array();$from[]="<<number>>";$from[]="<<rank>>";$from[]="<<initials>>";$from[]="<<family>>";$from[]="<<datef>>";$from[]="<<datet>>";$from[]="<<dates>>";//and so on to have all the fields you want to replace$to=array();$to[]=$number;$to[]=$rank;$to[]=$initials;$to[]=$family;$to[]=$datef;$to[]=$datet;$to[]=$dates;//And so on to have all the strings you have to put in place of the fields$string=str_replace($from,$to,$string);$fp = fopen( "$file2" , "w" );fputs( $fp, $string );fclose( $fp );copy ($file2, $file3);$fileatt = "files/leave1.htm"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "leave1.htm"; // Filename that will be used for the file as the attachment $email_from = "Test"; // Who the email is from $email_subject = "Leave Application"; // The Subject of the email $email_message = "This is a Leave Application."; // Message that the email has in it $email_to = "cm44750@cadetnet.gov.au"; // Who the email is too $headers = "From: ".$email_from; $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $email_message .= "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_message . "\n\n"; /********************************************** First File ********************************************/ $fileatt = "files/leave1.htm"; // Path to the file $fileatt_type = "application/octet-stream"; // File Type $fileatt_name = "leave1.htm"; // Filename that will be used for the file as the attachment $file = fopen($fileatt,'rb'); $data = fgets($file,filesize($file)); fclose($file); $data = chunk_split(base64_encode($data)); $email_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . //"Content-Disposition: attachment;\n" . //" filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; /********************************************** Second File ********************************************/ // To add more files just copy the file section again, but make sure they are all one after the other! If they are not it will not work! $ok = @mail($email_to, $email_subject, $email_message, $headers); if($ok) { echo "<font face=verdana size=2>The Leave Application was successfully sent!</font>"; } else { die("Sorry but the Leave Application could not be sent. Please go back and try again!"); } unlink( "$file2" );unlink( "$file3" );?> Now the problem i face is the errors i get with it. these errors being: Warning: filesize(): Stat failed for Resource id #7 (errno=2 - No such file or directory) in /home/tuddy/public_html/pro.php on line 78 Warning: fgets(): Length parameter must be greater than 0. in /home/tuddy/public_html/pro.php on line 78Line 78 is: $data = fgets($file,filesize($file)); I have studied and changed this code around and can't get it to work, the attachment i get is blank, but its supposed to have the placeholders replaced? Any ideas? Notice from cmatcmextra: Added codebox and quote tags. Warned. Also I'm deducing the credits earnt for this post. Edited August 14, 2005 by cmatcmextra (see edit history) Share this post Link to post Share on other sites
karlo 0 Report post Posted August 13, 2005 I suggest using the include() function.. anyways, try using the QUOTE bbCode when posing a PHP code. Because a moderator or an Admin might warn you. Share this post Link to post Share on other sites
Tyssen 0 Report post Posted August 13, 2005 (errno=2 - No such file or directory) in /home/tuddy/public_html/pro.php on line 78Quick guess is because the path has to be the full path, ie not files/filename.htm but /home/tuddy/public_html/files/filename.htm. Share this post Link to post Share on other sites
tuddy 0 Report post Posted August 14, 2005 I suggest using the include() function.. anyways, try using the QUOTE bbCode when posing a PHP code. Because a moderator or an Admin might warn you. 173882[/snapback] How would i use include() within my script? I dont want any of the script to show something in the browser, which what include() would do, wouldn't it? The way to get rid of my errors is to have the values replaced, but why won;t my script replace them?, it just writes over everything with a blank page. :S Share this post Link to post Share on other sites