如何使用 PHP 将文本从用户生成的 .txt 文件导入到 div 中?

发布于 2024-10-18 17:57:54 字数 1379 浏览 3 评论 0原文

我使用 Flash 和 Dreamweaver 制作了一张电子贺卡。电子贺卡上有一个需要填写的表格,包括您的姓名、电子邮件、评论以及您要向其发送电子贺卡的人的姓名和电子邮件。 (http://ornryd.com/test/playfulform/) 当您按下“提交”按钮时,它会向收件人发送一封电子邮件,并在我的服务器上创建一个包含该信息的 .txt 文件。

.txt 文件具有由以下方式生成的唯一名称:

$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 );

在电子邮件中,有一个指向“page2”的链接,我希望表单中的注释显示在 a 或 flash 文本字段中, (http://www.ornryd.com/test/player/index.php)< /a>

问题是我不知道如何将 .txt 文件中用户生成的文本导入到第 2 页的 div 中。

我希望您明白我想要做什么。如果没有的话,我可以试着把你不明白的事情描述得更详细一些。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪心 2024-10-25 17:57:54

您需要将链接中的文件名作为参数发送。然后您的 PHP 文件将需要读取该参数,并打开相应的文件。

类似

链接的东西是
http://www.ornryd.com/test/readcard?file=afilename.txt

并且你的 PHP 会寻找它,

$filename = isset($_GET['file']) ? $_GET['file'] : '';
$card = '';
if (file_exists($filename)) {
   $card = file_get_contents($filename);
} 

现在你已经将卡片内容作为变量,你可以在任何你想要的地方显示它。

注意这只是一个示例。您必须记住的一些事情是

  1. 这将允许人们查看其他文件,除非您发送某种安全令牌(人们可以更改文件以查看其他人的卡)

  2. 您应该清理文件名位,以便文件的路径始终仅指向目录你想要的。因此,请删除路径中的“../”之类的内容。

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

  1. 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)

  2. 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.

﹂绝世的画 2024-10-25 17:57:54

如果您发送链接,请在 URL 中包含 $CreateEcard 以找到正确的链接,例如 blah.php?file=12345

在您的 blah.php 确保检查 $_GET['file'] 是一个数字 (intval),然后使用 file_exists 检查 $ _GET['文件'] 。 “.txt” 存在,然后运行 ​​file_get_contents检索文本文件的内容。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文