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

  • Home
  • SEARCH
  • 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 8202113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:03:29+00:00 2026-06-07T07:03:29+00:00

I write php code to allow user to submit image and upload it to

  • 0

I write php code to allow user to submit image and upload it to the server. I get it working and the server receives the image. But it seems like the server is accepting even .avi and .flv files. I do write if/else statement for checking whether a file is an image, but why it doesn’t work? Thank you

This is my php code

$tmpPath = $_FILES["image"]["tmp_name"];
$movedPath = "submit-img/" . $_POST["category"] . "/" . $_FILES["image"]["name"];

$fullURL = parse_url($_SERVER['HTTP_REFERER']);
$query = explode("&", $fullURL["query"]); //only choose first query
$prevPage = "gallery.php" . "?" . $query[0];

//I get the file type here
$fileType = strpos($_FILES["image"]["type"], "image/");

//if its not an image then redirect to the previous page and send a message
if ($fileType === false || ($_FILES["image"]["size"]) == 0 || $_FILES["image"]["size"]/1024 > 5000){
    $prevPage = $prevPage . "&imgSubmit=none#imgSubmitForm";
    header("Location: " . $prevPage);
}else if ($_FILES["image"]["size"] > 0){ //if file is an image
    if (!is_file($movedPath)){
        move_uploaded_file($tmpPath, $movedPath);
    }else{
        while (is_file($movedPath)){    
            $extension = strrchr($movedPath, ".");
            $movedPath = str_replace($extension, "", $movedPath) . "1" . $extension;
        }
        move_uploaded_file($tmpPath, $movedPath);
    }
    $prevPage = $prevPage . "&imgSubmit=submitted#imgSubmitForm";
    header("Location: " . $prevPage);

}

  • 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-07T07:03:30+00:00Added an answer on June 7, 2026 at 7:03 am
    }else if ($_FILES["image"]["size"] > 0){ //if file is an image
    

    The comment on this line is fundamentally misleading. The size key in $_FILES is the size of the file in bytes; it has nothing to do with whether the “file is an image”. (In particular, it is not the physical size of the image.)

    If you need to test whether a file is an image, your best bet is to use the getimagesize function. This function will return the size of an image if it’s an image type that PHP recognizes, or zero if it doesn’t appear to be an image.

    Do not use the type field of the $_FILES array to determine whether a file is an image. This field is populated by the browser, not by the server, and may contain misleading and/or flat-out incorrect information.

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

Sidebar

Related Questions

<a href=details.php?phoneid=1><img src=phone01.jpg></a> When I write the code like this it's working fine. But
I need to write php code to identify common e-mail errors, like inbox full
I have a PHP image upload system which allows a user to upload various
hi all i am trying to upload image file from sdcard to php server
I want to write a php code that can search for multiple keywords separated
I am using Windows 2003 to write some PHP code. I use XAMPP Portable
When writing PHP code for any given project, do you find you can write
i write below code for sending id to another php file function selectCheckBox(k) {
I have script which allows the user to choose an image and write something
I am making a simple Dynamic Website using PHP, where i allow the user

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.