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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:20:36+00:00 2026-06-02T07:20:36+00:00

Thanks in advance. I have a php image uploader that I built, which is

  • 0

Thanks in advance.

I have a php image uploader that I built, which is working just fine. However I tried uploading a .JPG extension image and it did not work. Please note I mean capital JPG and not lowercase jpg. .png, .jpg, .gif all work fine and get uploaded, the thumbnails are created and what not. It is the capital .JPG that isn’t working for some reason. See my code below. Is it a different mime type?

The queries (which I removed for security purposes) work just fine. The information is stored. It is the moving of the file and thumbnail to the correct folders that isn’t happening due to the capital .JPG extension. Any help would be great, I did some research and tried the Apache add type JPG and that did not work.

if(isset($_POST['submit']))
{

    $getcatid = mysql_query('"query here"');
    $rescatid = mysql_fetch_assoc($getcatid);
    $catid = $rescatid['catid'];

    if ((($_FILES['file']['type'] == "image/png") || 
        ($_FILES['file']['type'] == "image/jpeg") ||
        ($_FILES['file']['type'] == "image/pjpeg")) && ($_FILES['file']['size'] < 2097152))
    {

        if (file_exists("location here".time().'_'.$_FILES["file"]["name"]))
            {
                echo '<div class="error">'.$_FILES["file"]["name"].' already exists</div>'; 

            }
        else
            {

                    $filename = time().'_'.$_FILES['file']['name'];  
                    $source = $_FILES['file']['tmp_name'];  
                    $target = 'location here'.$filename;  

                    move_uploaded_file($source, $target); 

                    createThumbnail($filename);  

                $date = time();
                $store = '"query here"';';

                mysql_query ($store);

                echo '<div class="success">Image added</div>';

            }
    }

    else
    {
        echo '<div class="error">Invalid file, only jpg, jpeg, or png file types allowed</div>';
    }

}

if(isset($_POST['multisubmit']))
{

    $getcatid = mysql_query('"query here"');
    $rescatid = mysql_fetch_assoc($getcatid);
    $catid = $rescatid['catid'];


    for($i=0;$i< count($_FILES['multifile']['type']);$i++)
    {

        if ((($_FILES['multifile']['type'][$i] == "image/png") || 
        ($_FILES['multifile']['type'][$i] == "image/jpeg") || 
        ($_FILES['multifile']['type'][$i] == "image/pjpeg")) && 
        ($_FILES['multifile']['size'][$i] < 2097152))
        {

            $filename = time().'_'.$_FILES['multifile']['name'][$i]; 
            $source = $_FILES['multifile']['tmp_name'];   
            $target = 'location here'.$filename;  

            if(move_uploaded_file ($_FILES['multifile']['tmp_name'][$i],$target))
            {
                createThumbnail($filename);  

                $date = time();
                $store = '"query here"';';

                mysql_query ($store);

                echo '<div class="success">Image: '.$filename.' added, view individual album to edit image descriptions</div>';
            } 
            else
            {
            echo '<div class="error">Invalid file'.$filename.', only jpg, jpeg, or png file types allowed</div>';
            }        
        }
    }
}

Thumbnail function if it helps:

function createThumbnail($filename) {  
$final_width_of_image = 160;  
$path_to_image_directory = 'path here';  
$path_to_thumbs_directory = 'path here';

if(preg_match('/[.](jpg)$/', $filename)) {  
    $im = imagecreatefromjpeg($path_to_image_directory . $filename);  
} else if (preg_match('/[.](gif)$/', $filename)) {  
    $im = imagecreatefromgif($path_to_image_directory . $filename);  
} else if (preg_match('/[.](png)$/', $filename)) {  
    $im = imagecreatefrompng($path_to_image_directory . $filename);  
}  

$ox = imagesx($im);  
$oy = imagesy($im);  

$nx = $final_width_of_image;  
$ny = floor($oy * ($final_width_of_image / $ox));  

$nm = imagecreatetruecolor($nx, $ny);  

imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);  

if(!file_exists($path_to_thumbs_directory)) {  
  if(!mkdir($path_to_thumbs_directory)) {  
       die("There was a problem. Please try again!");  
  }  
   }  

imagejpeg($nm, $path_to_thumbs_directory . $filename, 100);  

}
  • 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-02T07:20:37+00:00Added an answer on June 2, 2026 at 7:20 am

    From your thumbnail code:

    if(preg_match('/[.](jpg)$/', $filename)) 
    

    That will only match lowercase ‘jpg’. If you want to match upper or lowercase, you can add the /i flag for case-insensitivity:

    if(preg_match('/[.](jpg)$/i', $filename)) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks in advance! I have a simple mysql and php blog that I built
I have an image uploader that runs on a separate PHP script, and then
Thanks in advance.. I have a windows phone application. In that I am showing
First hi and thanks in advance in ASP.NET : assume that i have a
I have a PHP script that displays an image(according to the current time) and
I have a php file which has the following path Shubhmangalam/admin/welcome_image_edition/delete_image.php and an image
thanks in advance for the replies.... I have started to create a network topology
First, thanks in advance for taking the time to read through this. I have
I am using c# .net. Thanks in advance for any help. I have searched
I'm working with yii framework forms and I have a form like this: <?php

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.