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 8535669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:29:07+00:00 2026-06-11T10:29:07+00:00

I have been researching securely uploading images, and it has become apparent that actually

  • 0

I have been researching securely uploading images, and it has become apparent that actually serving the images is where most of the risk is for rogue PHP files that could compromise the server.

Many are suggesting that having a image processing script e.g getimage.php?i=575748 which would lookup in the database 575748 and actually return myphoto.jpg (whithout the user knowing the location of the origional image) is much more secure.

Can any point me in the right direction of what sort of things I should be implementing in the script? I know setting the content type headers is a must, but is this enough to stop code executing?

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-11T10:29:09+00:00Added an answer on June 11, 2026 at 10:29 am

    and it has become apparent that actually serving the images is where
    most of the risk is for rogue PHP files that could compromise the
    server

    This only happens if two conditions are met:

    • You allow uploading of non-image files
    • Downloading is done through a direct link

    Thwart one of these and the danger disappears. Of course closing both is better.

    The database solution aims at disrupting condition #2, but you can also check, when uploading the image, that it is indeed an image using the getImageSize() function. Or trying to load the image with imageCreateFromJPEG() or other appropriate function.

    If the object loaded is not an image, just display “Sorry, image is corrupt”. This both protects your users against uploading broken images and you against someone uploading a rogue PHP file (or maybe a copyrighted video or cracked executable or…).

    UPDATE: you can also obfuscate an already existing upload-and-download facility:

    Say that currently you upload the user image, assign to it a unique ID, save it as ./images/UNIQUEID.jpg, and serve to the user http://www.yoursite.com/images/UNIQUEID.jpg as URL.

    • You apply a .htaccess so that access to ./images/whatever is redirected to ./images/index.php?ID=whatever
    • You create a index.php script that takes “whatever”, extracts the image ID, and outputs the image.

    All old URLs will continue to work and appear to directly load the image, but what they’re actually doing is invoke a PHP script that checks for the image and sends it along as a bytestream, without interpreting.

    You’ll want to be setting ETag to the ID, Last-Modified to file_mtime() of the image file, and Content-Length to the file size. Also, you may want to check the incoming header If-Modified-Since and If-None-Match: if the date of the file corresponds to IMS or the IFN value corresponds to the ID, you can send a HTTP/304 Not Modified answer instead of the image, saving considerable bandwidth.

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

Sidebar

Related Questions

I have been researching, SQL Server 2012 (aka Denali) and Microsoft has a pre-release
I have been researching but I am clueless. I know that MD5 can have
I have been researching a way to get the SQL statements that are built
I have been researching in to using Background Intelligent Transfer Service . Most articles
I have been researching for a while and have actually created a prototype ASP.NET
I have been researching for over an hour and finding great samples of how
I have been researching all over the internet about this, and unfortunately cannot find
I have been researching this issue pretty extensively and cannot seem to find an
I have been researching intently and have been unable to find a solution to
I have been researching OpenGL programming on Mac OS X. While a fair amount

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.