Question

Can't upload Image to server

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


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

This comment has been deleted