简体   繁体   English

在安全模式下使用 PHP 写入文件

[英]Write file with PHP in safemode

I can't use fopen because PHP is in safemode and admin wont change this.我不能使用 fopen,因为 PHP 处于安全模式,管理员不会更改它。 How can I write a static html file using php?如何使用 php 编写 static html 文件?

With difficulty, unfortuantely.困难重重,不幸的是。 If your sysadmin has not set up user permissions that allow you to do this, then there's no general workaround.如果您的系统管理员没有设置允许您执行此操作的用户权限,则没有一般的解决方法。 Other answers (eg FTP-ing) may work in certain circumstances (again, if user permissions allow it).其他答案(例如 FTP-ing)可能在某些情况下有效(同样,如果用户权限允许)。

The only foolproof solution is to talk to the sysadmin.唯一万无一失的解决方案是与系统管理员交谈。

You can only open (and thus write) to files in directories, that are permitted by the safemode settings.您只能打开(并因此写入)安全模式设置允许的目录中的文件。

You can still do with safe mode enabled您仍然可以启用安全模式

Beware: Safe mode will not permit you to create new files in directories which have different owner than the owner of the script.注意:安全模式将不允许您在与脚本所有者不同的目录中创建新文件。 This typically applies to /tmp, so contrary to Unix intuition, you will not be able to create new files there (even if the /tmp rights are set correctly).这通常适用于 /tmp,因此与 Unix 的直觉相反,您将无法在那里创建新文件(即使 /tmp 权限设置正确)。

If you need to write into files in /tmp (for example to put logfiles of your PHP application there) create them first on the command line by doing a如果您需要写入 /tmp 中的文件(例如,将 PHP 应用程序的日志文件放在那里)首先在命令行上通过执行

touch /tmp/whatever.log触摸/tmp/whatever.log

as the same user who owns the PHP script.作为拥有 PHP 脚本的同一用户。 Then, provided the rest is configured correctly, the PHP script will be able to write into that file.然后,如果 rest 配置正确,PHP 脚本将能够写入该文件。

http://php.net/manual/en/features.safe-mode.php http://php.net/manual/en/features.safe-mode.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM