我可以在Heroku上创建一个带有php脚本的.txt文件
我正在尝试使PHP脚本在Heroku上创建.txt
文件。它没有显示任何错误消息,但是当我去查看它是否通过在控制台中运行ls
创建文件时,那里什么也没有。
有人可以帮我吗?
<html>
<body>
<?php
// the message
$_msg = $_GET["email"];
$_subject = $_GET["name"];
$myfile = fopen($_subject .=".txt", "w") or die("Unable to open file!");
$txt = $_msg;
fwrite($myfile, $txt);
fclose($myfile);
header("Location: index.php", TRUE, 301);
exit();
?>
</body>
</html>
I am trying to make a PHP script create a .txt
file on Heroku. It doesn't show any error message, but when I go to see if it created the file by running ls
in the console there is nothing there.
Anyone can help me please?
<html>
<body>
<?php
// the message
$_msg = $_GET["email"];
$_subject = $_GET["name"];
$myfile = fopen($_subject .=".txt", "w") or die("Unable to open file!");
$txt = $_msg;
fwrite($myfile, $txt);
fclose($myfile);
header("Location: index.php", TRUE, 301);
exit();
?>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您在此处说“在控制台”中时,我猜什么 都没有。 或类似。
HEROKU RUN
不连接到您的运行dyno,而是在一次性的dyno中运行命令。 dynos 也不共享文件系统,即使在一个dyno中,文件系统也是ephemeralserystems emphemeralseral is ephemeralSeralseral :换句话说,您的PHP脚本生成的文件与您通过
Heroku Run Bash
看到的文件系统完全不同,并且您对任何文件系统的任何更改都将经常且不可预测。如果您想长期持续存在文件,则需要将它们保存在其他地方。一个常见的选择是使用 Amazon S3 。或者,取决于您存储的数据类型,a 数据存储可能是更合适。
I'm guessing when you say "in the console" here you mean by running
heroku run bash
or similar.heroku run
doesn't connect to your running dyno, but instead runs the command it is given in a one-off dyno. Dynos don't share filesystems, and even within one dyno the filesystem is ephemeral:In other words, the file your PHP script generates is on a completely different filesystem from the one you see via
heroku run bash
, and any change you make to either filesystem will be lost frequently and unpredictably.If you want to persist files long-term you'll need to save them somewhere else. A common choice is to use Amazon S3. Or, depending on the type of data you are storing, a data store might be a better fit.