Report this

What is the reason for this report?

Can't upload Image to server

Posted on July 18, 2015

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



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

This comment has been deleted

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!

– Regards Saurabh

Servopia.com Managed Cloud Hosting For PHP Applications

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:

/path/to/your/website
/path/to/upload-folder

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!

– Regards Saurabh

Servopia.com Managed Cloud Hosting For PHP Applications On DigitalOcean IaaS

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.