Nginx – Upload file to nginx server through php/html form

filesinstallationnginxupload

I think this is very popular question, however I can't find information I interested in, hope you help me.
I new to server administration things, so don't throw stones at me:)
I install nginx to my debian virtual server, and already install php, mysql and all I was need to. But when I start use my php scripts I found that I can't upload files through html form.

I made some test page and I see that, after form was submitted I can see the $_FILES['tmp_name'], but PHP function move_uploaded_file doesn't work. It doesn't moved the file.

So that's why I start googling and find lot of info about nginx_upload module and so on.
Is it posible to config nginx to upload a file, or I must install nginx_upload module to do so?

What I must to do for allow upload files to my nginx server. Thank you.

Best Answer

Since $_FILES['fieldname']['errors'] contains 0 (which is UPLOAD_ERR_OK), the actual upload has succeeded. What's failing is the attempt to move the temporary file to the location you specified, which is why move_uploaded_file() is returning false. You're doing something like this:

move_uploaded_file($_FILES['fieldname']['tmp_name'], '/srv/www/uploads')

The most likely problem is that PHP doesn't have write permission to the directory you specified as the second parameter. Find out what user PHP is running as (probably something like www-data), and make sure that that user has write permission:

chown -R www-data /srv/www/uploads
chmod -R u=rwX,g=rwX,o=rX /srv/www/uploads
Related Topic