我使用托管服务器。我想简单地用 PHP 打开一些文本文件并将一些数据写入我服务器的数据库中。 这与任何前端/用户事件无关。 我以前从未这样做过,我不确定服务器上的最佳位置在哪里...... 我在顶层看到目录,例如 PHP 是吗?
我还应该补充一点,我不明白如何在非 HTML 表单上下文中执行 PHP 脚本
也请多多指教 对不起,如果这很愚蠢。
最佳答案
what directory should I put this script in? I would like to simply open some text files with PHP and write some of the data into my local database
我的项目目录中通常有一个 bin
目录(在 webroot
旁边)。
I see directories at top level such as PHP is that it?
我看不出有任何理由首先要有一个顶级 PHP 目录。
I should also add that I do not understand how to execute a PHP script in a non-HTML form context
假设它有一个 shebang行,你只需运行它:
~/projects/myProject/bin/myScript.php
或者(不需要 shebang):
php ~/projects/myProjects/bin/myScript.php
关于php - 我应该把这个脚本放在什么目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6743086/