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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:39:53+00:00 2026-06-08T09:39:53+00:00

Hi I based this function from the one I’ve found on web and tried

  • 0

Hi I based this function from the one I’ve found on web and tried modifying it up for my PHP page for uploading of their icons but I want to limit the user from uploading an image which should only size 100x100px. Well I just call it using this:

uploadImage($id,$_FILES['upload']['name'],$_FILES['upload']['tmp_name']);

This is the function I made:

 function uploadImage($new_name,$imagename,$tmp_name){

 if($tmp_name!=null||$tmp_name!=""){
     list($width, $height, $type, $attr) = getimagesize($tmp_name);
         if($width==100&&$height==100){
          $image1 = $imagename;

          $extension = substr($image1, strrpos($image1, '.') + 1);
          $image = "$new_name.$extension";
          $folder = "Images/"; 
                  if($image) { 
                    $filename = $folder.$image; 

                    $copied =  copy($tmp_name, $filename); 
                  }
                  else echo "image not uploaded.";
          }
          else
            echo "upload only 100x100px image!"; 
    }

}

Now the problem is that even if I uploaded an image which exceeds the 100 x 100px dimensions it still proceeds without returning any errors and now I’m lost with it.

  • 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-08T09:39:55+00:00Added an answer on June 8, 2026 at 9:39 am

    well, you can also resize the image after upload.

    function createFixSizeImage( $pathToImages, $pathToFixSizeImages, $Width ) 
    {
    
      // open the directory
      $dir = opendir( $pathToImages );
    
      // loop through it, looking for any/all JPG files:
      while (false !== ($fname = readdir( $dir ))) {
    
    
      $image_info   = getimagesize( "path/to/images/".$fname );
      $image_width  = $image_info[0];
      $image_height = $image_info[1];
      $image_type   = $image_info[2];
    
    
      switch ( $image_type )
      {
    
        case IMAGETYPE_JPEG:
    
    
        // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if ( strtolower($info['extension']) == 'jpeg' ) 
        {
    
          // load image and get image size
          $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
    
          $width = imagesx( $img );
          $height = imagesy( $img );
    
          // give the size,u want
          $new_width = 100;
          $new_height = 100;
    
          // create a new temporary image
          $tmp_img = imagecreatetruecolor( $new_width, $new_height );
    
          // copy and resize old image into new image 
          imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
    
          // save Fix Size Images into a file
    
          imagejpeg( $tmp_img, "{$pathToFixSizeImages}{$fname}" );
    
        }
          break;
    
    
    
         case IMAGETYPE_PNG:
             // parse path for the extension
        $info = pathinfo($pathToImages . $fname);
        // continue only if this is a JPEG image
        if ( strtolower($info['extension']) == 'png' ) 
        {
    
          // load image and get image size
          $img = imagecreatefrompng( "{$pathToImages}{$fname}" );
    
          $width = imagesx( $img );
          $height = imagesy( $img );
    
    
          $new_width = 100;
          $new_height = 100;
    
          // create a new temporary image
          $tmp_img = imagecreatetruecolor( $new_width, $new_height );
    
          // copy and resize old image into new image 
          imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
    
          // save Fix Size Images into a file
    
          imagejpeg( $tmp_img, "{$pathToFixSizeImages}{$fname}" );
    
        }
          break;
    
        case IMAGETYPE_BMP:
          echo "bmp";
          break;
    
    
    
        default:
          break;
      }
    }
      }
      // close the directory
      closedir( $dir );
    }
    
    createFixSizeImage("path","path/to/images/to/be/saved",100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm inserting multiple rows from one table to another, based on ID. For this
I wrote this function to make columns sortable. I want to rearrange divs based
This question is based on this thread . The code function man() { man
This question is based on the thread . I have the shell function function
I am writing a document based application on OS X. One feature oft this
I have the following setup: class.staff.php This defines many variables, the one I'm working
This recursive function ( search_Bases ) would hopefully iterate through each base class and
I have this base type: typeA = function () { }; typeA.prototype = {
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
I've written a pair of AES encrypt/decrypt functions based on this example . It

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.