Skip to content
Advertisement

Image upload on linux server (PHP)

I am trying to upload image to server. The following code works when I use on local pc but when I try on server, image is not uploaded.

JavaScript

Advertisement

Answer

Do you have the same file permissions on server? Does folder /var/www/html/uploaded exist and is writable by web server user (usually www-data)?

Try running following command in server terminal:

JavaScript

Where www-data is used, change it with your own web server user.

“FIXED” SCRIPT:

JavaScript

You should write additional checks, so you know where your application fails.

Regarding security, you should never trust user. In this case we used filename ($_FILES['file_uploaded']['name'])provided by user, using which he could write and maybe even read outside of designated directory

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement