简体   繁体   English

文件上传在服务器中不起作用,但在本地工作

[英]File upload is not working in server but working locally

I have seen my phpinfo file,it has no tmp value set so I set it to /tmp 我看过我的phpinfo文件,它没有设置tmp值,所以我将其设置为/ tmp

upload_tmp_dir = "/tmp"

But still it is not working. 但是仍然无法正常工作。 My server is in Amazon ec2. 我的服务器在Amazon ec2中。

I have tried putting the upload_tmp_dir as "/var/www" (with no trailing slash ) ,but that too didn't work. 我尝试将upload_tmp_dir设置为“ / var / www”(不带斜杠),但是那也不起作用。 Do I need to set permissions to the tmp directory ? 我是否需要设置tmp目录的权限?

print_r($_FILES);

is giving 在给

enter code here
Array ( [upload_file] => Array ( [name] => ps.jpg [type] => image/jpeg [tmp_name] => /tmp/phpBcpdfP [error] => 0 [size] => 193728 ) )

and

 is_uploaded_file($_FILES['upload_file']['tmp_name'])

is giving the result 1 给结果1

It is probably a permission issue on the destination folder. 这可能是目标文件夹上的权限问题。

Do sudo chmod -R 777 /destination/folder and try again. 执行sudo chmod -R 777 /destination/folder然后重试。 Then it should work. 然后它应该工作。 If you still can't upload your file, maybe the permission problem is on a parent directory. 如果仍然无法上传文件,则可能是父目录存在权限问题。

After that, find which user (and its group) is the owner of your uploaded file. 之后,找到哪个用户(及其组)是您上载文件的所有者。

Then set the permission back, and change the owner of your directory : sudo chown -R owner_user.group /destination/folder . 然后放回该权限,并更改目录的所有者: sudo chown -R owner_user.group /destination/folder

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

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