简体   繁体   English

PHP将不会上传图片?

[英]php won't upload images?

I have a php script with no erros (I tested it in other servers), the problem is, in this server I cannot upload images from php. 我有一个没有错误的php脚本(我在其他服务器上进行了测试),问题是,在此服务器上,我无法从php上传图像。

I add 755 to folder, php.ini file upload is on, max file size is 12mb. 我将755添加到文件夹,开启了php.ini文件上传,最大文件大小为12mb。

I run this: 我运行这个:

chown apache /var/www/html/img-img/
chmod 755 /var/www/html/img-img/

but also didn't solve my problem. 但也没有解决我的问题

my php also try to create a folder to upload images inside img-img (no success): 我的php也尝试创建一个文件夹来上传img-img内的图像(没有成功):

 $pasta = date("dmy");
 $pasta_dir2 = "img-img/$pasta";
 if(!file_exists($pasta_dir2)){
  mkdir($pasta_dir2, 0755);
 }

I have this warnings: 我有这个警告:

move_uploaded_file(img-img/14719222_886454304825512_8860750091242176512_n.jpg): failed to open stream: Permission denied in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php 
PHP Warning:  move_uploaded_file(): Unable to move '/tmp/phptZYSam' to 'img-img/14719222_886454304825512_8860750091242176512_n.jpg' in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php

any ideas how to solve this without break server security? 任何想法如何解决此问题而不会破坏服务器安全性?

检查img-img文件夹是否存在,并尝试使用chmod -R 0755 /var/www/html/对html的所有文件夹和子文件夹设置744权限

这解决了我的问题:我不知道它能做什么,但是可以工作...如果有人知道,请回答并让我知道。

sudo chcon -t httpd_sys_rw_content_t /var/www/html/img-img -R

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

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