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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:55:07+00:00 2026-05-19T02:55:07+00:00

I got my php upload form working (allowing .jpg), but am not sure how

  • 0

I got my php upload form working (allowing .jpg), but am not sure how to add .JPG (uppercase issue) or .jpeg.

Could someone please show me how to add these extensions to the following code?

<?php
//–°heck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file is JPEG image and it's size is less than 350Kb
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 16000000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved!";
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 15 Mb are accepted for upload";
  }
} else {
 echo "Error: No file uploaded";
}
?>

Thanks so much for your help and time!

  • 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-05-19T02:55:08+00:00Added an answer on May 19, 2026 at 2:55 am

    You would probably change line 6 from:

    if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
    

    to:

    if (($ext == "jpg" || $ext == "jpeg" || $ext == "JPG") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
    

    Although if you want to expand this further I’d recommend using an array of filetypes and checking the array, much easier to manage. Specifically using the in_array function http://php.net/manual/en/function.in-array.php

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

Sidebar

Related Questions

I've got this php code to send the users information from the contact form
I've got my php working to set a cookie storing the http_referer the visitor
I've got a php array (obtained through checkbox values in a form - as
I'm trying to upload a picture to a specific website using php cURL but
Ive been working on create a file upload form using PHPmailer to send as
I need to upload file the server via .php file, and i've got this
I've got a simple HTML file upload form. I'm using the jQuery validation plugin
I've got a simple HTML form, thus: <html> <head></head> <body> <form action=upload_file.php method=post enctype=multipart/form-data>
I'm trying to upload a file using PHP. My HTML page with the form
I got this php uploading script which is working fine on Mozilla, Chrome, Opera,

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.