写目录使用PHP:这是一个权限问题? [英] Write to Directory using PHP: Is this a permissions problem?
问题描述
我的PHP脚本写入一个文件,以便它可以创建一个JPG图片。
的fwrite($处理,$ GLOBALS ['HTTP_RAW_POST_DATA']);
FCLOSE($处理);
打印$ newfile中JPG。;
我已经把这个脚本一个新的服务器,不过像永远不会被保存在。该文件夹的权限将其保存到是755,但它并不拥有它。去年的时候,我觉得我通过更改目录的所有者到Apache,因为这是PHP运行作为什么固定的问题。因为我不是根,我不能再这样做。
首先,是否有其他解决?其次,如果我可以改变像上次目录的所有者将这一解决这个问题?
感谢所有的帮助
- 文件夹以777的更改权限(
rwxrwxrwx
) - 从PHP创建的mkdir 子目录
- 更改目录权限回755(
rwxr-XR-X
),甚至更好的711(RWX - X - X
) - 。
从现在开始保存您的照片在子目录,这是目前由WWW的数据拥有(或任何用户Apache使用)
BTW。您可以按照code减少:
的fopen($ newfile中'JPG。,世行);
FWRITE($处理,$ GLOBALS ['HTTP_RAW_POST_DATA']);
FCLOSE($处理);
打印$ newfile中JPG。;
到
的file_put_contents($ newfile中。。JPG,
的file_get_contents('PHP://输入',
FILE_BINARY)
FILE_BINARY)
My PHP script writes to a file so that it can create a jpg image.
fwrite($handle, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($handle);
print $newfile.'.jpg';
I have put this script on a new server however the image never gets saved. The permission of the folder it saves to is 755 but it does not own it. Last time, I think I fixed the issue by changing the directory owner to apache as this is what PHP runs as. I can not do the same again because I am not root.
Firstly., Is there another fix? Secondly, If I could change the owner of the directory like last time will this fix the issue?
Thanks all for any help
- change permissions of the folder to 777 (
rwxrwxrwx
) - from PHP create subdirectory with mkdir
- change your directory permissions back to 755 (
rwxr-xr-x
) or even better 711 (rwx--x--x
) - from now on save your images in the subdirectory, which is now owned by www-data (or whichever user Apache uses).
BTW. you can reduce following code:
fopen($newfile.'.jpg','wb');
fwrite($handle, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($handle);
print $newfile.'.jpg';
to:
file_put_contents($newfile.'.jpg',
file_get_contents('php://input',
FILE_BINARY),
FILE_BINARY)
这篇关于写目录使用PHP:这是一个权限问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!