简体   繁体   中英

Write file with PHP in safemode

I can't use fopen because PHP is in safemode and admin wont change this. How can I write a static html file using php?

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

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

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

touch /tmp/whatever.log

as the same user who owns the PHP script. Then, provided the rest is configured correctly, the PHP script will be able to write into that file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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