How do I import text from a user generated .txt-file to a div with PHP?
I've made an Ecard using Flash and Dreamweaver. On the Ecard is a form to fill out, your name, your email, a comment, and the name and email to the person you are sending the ecard to. (http://ornryd.com/test/playfulform/) When you push the "Submit"-button it sends an email to the receiver, and it creates a .txt file on my server with the info.
The .txt-file has a unique name generated by:
$mailCount = $_POST['me_count'];
$senderName = $_POST['me_name'];
$senderEmail= $_POST['me_email'];
$senderComm = nl2br($_POST['me_com']);
$date = date("l jS F H:i:s");
$ToSubject = "Email From $senderName via $webname";
$EmailBody = "";
$emailCount = 0;
$CreateEcard = date(U);
$filename = $CreateEcard.".txt";
$senderName = stripslashes($FromName);
$senderComm = stripslashes($senderComm);
$id = stripslashes($id);
$Today = (date ("l dS of F Y ( h:i:s A )",time()));
$Created="Ecard Created on $Today";
$EcardNum = $EcardSelect;
$EcardText = "&senderName=$senderName&FromEmail=开发者_运维问答$FromEmail&Comment=$senderComm&Created=$Created";
$fp = fopen( "./formText/$filename","w");
fwrite($fp, $EcardText, 10000);
fclose( $fp );
In the email there's a link to "page2" where I want the COMMENT from the form to display in a or in a flash-text field, (http://www.ornryd.com/test/player/index.php)
The problem is that I don't know how to import the user generated text in the .txt-file to a div on page 2.
I hope you understand what I want to do. If not, I can try to describe the things you don't understand a bit more.
You'll need to send the filename in the link as a param. And then your PHP file will need to read that param, and open the appropriate file.
something along the likes of
the link would be http://www.ornryd.com/test/readcard?file=afilename.txt
and your PHP would look for it
$filename = isset($_GET['file']) ? $_GET['file'] : '';
$card = '';
if (file_exists($filename)) {
$card = file_get_contents($filename);
}
now you have the card contents as a variable, you can display it wherever you want.
NOTE This is only an example. A few things you have to keep in mind is
This will allow people to look at other files unless you send some kind of security token (people can change the file to look at someone else's card)
You should be sanitizing the filename bit so that the path of the file always points only to the directory you want. So remove stuff like '../' that is in the path.
If your sending a link then include the $CreateEcard
in the URL to find the right one e.g. blah.php?file=12345
In your blah.php
make sure you check that $_GET['file']
is a number (intval
) then use file_exists
to check $_GET['file'] . ".txt"
exists and then run file_get_contents to retrieve the contents of the text file.
精彩评论