Can't upload Image to server

Posted July 18, 2015 30.6k views

I’m making a simple PHP application which can upload an image to server.

I’m using Digital Ocean. They are great especially the support team.

I uploaded via FileZilla, my folder’s name “ PHPFileUpload”, in this folder contain a sub folder uploads to contain image which could be uploaded, file index.html to show the button select image to upload and file upload.php.

I did it in my localhost, everthing work well, but when I did it in real server. I mean Digital Ocean, it didn’t work.

I spent for one day to solve it, but I still can’t.

Please help me to fix it. Thank all Sorry about my english, it is not native

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

Did you checked folder permissions? While to allow upload your folder permissions must be set to 777. To do so, follow this:

  • Login to terminal (with sudo privileges) through a client like PuTTY or you may directly use DOs control panel terminal
  • Run this command:
sudo chmod 777 /path/to/upload/folder

Once you run this command, the folder permissions will be set to 777 that allows uploading file to your server by anyone. Please note, as this is a security risk, you should not have this upload directory/folder inside of your hosting folder (which is generally /var/www).

Hope this helps!

Managed Cloud Hosting For PHP Applications

  • Hey Saurabh.
    Unbelievable !!. I spent for two day to fix this problem, it is very frustrating and thank god you are here.
    I fixed it with your great help,.
    Thank you so much.

    One more thing.
    “ you should not have this upload directory/folder inside of your hosting folder (which is generally /var/www).”
    What doen’t this mean ? and what I should to do.
    I just programming in Server and my knowledge is limited.
    Sorry about my English, it is not native

  • Thanks! Working for me.

    • Hello, I’m facing the same issue on my .net core angular web app hosted on an ubuntu lamp server. so my question is, can I use the same solutions provided here since my project isn’t a PHP project?

Glad that it worked :)

Well, that’s a security concern. If your upload folder is inside of your directory which serves your website, then anyone can upload anything to this folder, as the directory permissions are set to 777. This is dangerous!

This folder should be outside of your website directory so your website directory is isolated.

When I say outside, the structure of your website directory & upload folder will be like this:


As you can notice, that the directory structure shows that your upload folder is a step above or say, outside of your website directory. This way, even if certain file is purposefully uploaded by a visitor to exploit your server, the website directory will be safe. Although this is not the only way to protect your server but, is the right way to do it.

If you have used WHMCS, you would notice how they suggest to put upload folder outside of their install directory!

Hope it resolves your query!

Managed Cloud Hosting For PHP Applications On DigitalOcean IaaS