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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:17:17+00:00 2026-06-18T05:17:17+00:00

My website having uploading profile image section for members and i’ve used the following

  • 0

My website having uploading profile image section for members and i’ve used the following code.

Form Code

<form action="send.php" method="post" enctype="multipart/form-data" name="send" id="send">
    Your Image : <input type="file" name="pic" id="pic"/>
    <input type="Submit" name="Submit" value="Submit"/>
</form>

PHP Code send.php

$ImageName = $_FILES[pic][name]; 
if(!empty($ImageName) && $_FILES[pic][type] == "image/jpeg" || $_FILES[pic][type] == "image/png" || $_FILES[pic][type] == "image/gif" || $_FILES[pic][type] == "image/bmp"){
    $t = time();
    $NewImageName = "$t$ImageName"; // image new name
    copy($_FILES[pic][tmp_name], "users/$NewImageName"); // copy it to directory
} else {
    echo "no upload done";
}

But someone by using firefox extension manage to bypass it and uploaded php file
Who uploaded the file to my website sent me message said “you only check for type !”
and said ” i used firefox extension that can fake input fields and passed PHP file “.

So my question how do i protect my image upload form of the above code ? ~ 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-18T05:17:18+00:00Added an answer on June 18, 2026 at 5:17 am

    First I don’t think that’s is the valid format to read $_FILE variable

    $ImageName = $_FILES[pic][name]; 
    

    You should use

    $ImageName = $_FILES['pic'][name];
    

    Then I think it is improbable that someone can fake a server side check.

    Try to hack this, I use a *PATHINFO_EXTENSION* as mentioned in PHP.net Manual

    $validFormat = array("jpg","JPG","jpeg","JPEG","png","PNG","gif","GIF");    
    $path = pathinfo($_FILES['pic']['name'], PATHINFO_EXTENSION);
    if(in_array($path, $validFormat)){
    // it's okay
    }else{
    // Error
    }
    

    I’m working with this code since I discovered pathinfo a while ago and nobody hack it..

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

Sidebar

Related Questions

I'm building a website and having some problem. if the HTML code is like:
I'm having a problem concerning my website not running the code behind an ItemCommand
I have to create website in PHP, which need image editor functionality like image
I have been having lot of problems with users uploading images on my website.
I'm creating a video and image module for a website and am having trouble
All, On our website we are having issues with getting any jquery code to
I'm developing a website with following structure: click here . And I'm having some
I am trying to refactor some code in an ASP.Net website and having a
I created a ASP.NET3.5 website having a crystalreportviewer in it, it works fine if
I have a weird situation. A client of mine has a website having this

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.