我可以在Heroku上创建一个带有php脚本的.txt文件

发布于 2025-01-23 03:16:18 字数 602 浏览 0 评论 0原文

我正在尝试使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 技术交流群。

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

发布评论

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

评论(1

束缚m 2025-01-30 03:16:18

当我去查看它是否通过运行ls在控制台中创建文件时,那里没有什么

当您在此处说“在控制台”中时,我猜什么 都没有。 或类似。

HEROKU RUN不连接到您的运行dyno,而是在一次性的dyno中运行命令。 dynos 也不共享文件系统,即使在一个dyno中,文件系统也是ephemeralserystems emphemeralseral is ephemeralSeralseral :

每个Dyno都有自己的短暂文件系统,并具有最新部署的代码的新副本。在Dyno的一生中,其运行过程可以将文件系统用作临时刮擦板,但是在任何其他Dyno中的进程都看不到任何文件,并且在dyno停止或重新启动的那一刻,任何书面的文件都将被丢弃。例如,在任何时候由于申请部署而更换Dyno,并且每天大约作为正常Dyno管理的一部分发生这种情况。

换句话说,您的PHP脚本生成的文件与您通过Heroku Run Bash看到的文件系统完全不同,并且您对任何文件系统的任何更改都将经常且不可预测。

如果您想长期持续存在文件,则需要将它们保存在其他地方。一个常见的选择是使用 Amazon S3 。或者,取决于您存储的数据类型,a 数据存储可能是更合适。

when I go to see if it created the file by running ls in the console there is nothing there

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:

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted. For example, this occurs any time a dyno is replaced due to application deployment and approximately once a day as part of normal dyno management.

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.

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