Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8967285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:12:31+00:00 2026-06-15T17:12:31+00:00

Possible Duplicate: PHP image upload security check list I’m setting up a file upload

  • 0

Possible Duplicate:
PHP image upload security check list

I’m setting up a file upload form on my website, where the user can upload an image. For security, I check the image size and mime type before renaming the file and storing it.

What I’m worried about is how to prevent a user from constantly uploading different files and abusing my server. Is there a way to prevent this? I was thinking of keeping track of the user’s IP (via $_SERVER[“REMOTE_ADDR”] and $_SERVER[“HTTP_X_FORWARDED_FOR”]), with a timestamp for each upload and limitting uploads to X per hour. Any feedback or suggestions are appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:12:32+00:00Added an answer on June 15, 2026 at 5:12 pm

    Indeed, someone pointed out above $_FILES[x][‘type’] can be very easily and arbitrarily changed. Make sure you never rename anything .php or any other parsed/executed file such as .shtml … One way to avoid this is to always, when you serve the image back out to users, to use a single php script to serve them back and to use something like readfile() so the contents are never interpreted. Also, if you are only accepting images, you could use something as simple as getimagesize() to help validate that it is a real image. But once again, be wared, make sure that user uploaded contents can never be executed, specificially by uploading, and then accessing that uploaded file via their web browser. I am just making a point, I could imagine someone could take enough time to make a valid JPEG file that while it would parse via getimagesize() might contain harmful code if executed as .php. It’s a long shot, but you must be prepared for anything. 🙂

    On the subject of other types of abuse, you could use simple filters such as each IP only gets X bytes or total uploads (or both) per hour/day. If they exceed that limit, then use a very reliable captcha system such as reCAPTCHA. That way you never miss a legitimate request and abuse should be at a bare minimum, while not forcing every single image upload to go through a captcha.

    Additionally, remember do NOT take precedence of X-FORWARDED-FOR. I have actually seen code like this:

    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else { 
      $ip = $_SERVER['REMOTE_ADDR'];
    }
    

    This is extremely wrong. X-FORWARDED-FOR can be sent by a forwarding proxy server, if it feels like it. It can also be sent by absolutely anything and everything else to trick fools into thinking their IP is something that is actually not.

    As long as you use REMOTE_ADDR in combination with HTTP_X_FORWARED_FOR (and never trust HTTP_X_FORWARDED_FOR, only use it for a secondary reference), .. the chances of actual IP spoofing is next to nothing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: .htaccess rewrite image file to php script How can I execute a
Possible Duplicate: Max file number can php upload at same time I'm trying to
Possible Duplicate: PHP code can insert image to excel file and open it correctly
Possible Duplicate: Can anybody suggest the best image resize script in php? I'm still
Possible Duplicate: multi image upload wrong quantity on file-upload Hey so I have a
Possible Duplicate: How can I merge 3 images into 1 image via PHP? How
Possible Duplicate: How to save webpage as a image file using PHP? I would
Possible Duplicate: PHP - send file to user I have written a script that
Possible Duplicate: save image from php url using php How can i use php
Possible Duplicate: escapeshellarg() has been disabled for security reasons I've created an image upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.