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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:15:13+00:00 2026-06-03T07:15:13+00:00

I want to validate Image Resolution before upload an image in PHP through Javascript.

  • 0

I want to validate Image Resolution before upload an image in PHP through Javascript. In my php form , i want to upload two different images and both image have different resolution restriction.

I try the following code

PHP Code

echo "<form name='add' enctype='multipart/form-data' action='AppActions.php' method='post' onSubmit='return validate_create();'>";
echo "<div class='form_label'>Album Wrapper (Big Image) *</div>";
echo "<div class='form_input'><input type='file' name='bigimage' id='bigimage' />";

echo "<div class='form_label'>Album Wrapper (Small Image) *</div>";
echo "<div class='form_input'><input type='file' name='smallimage' id='smallimage' />;
echo "<input type='submit' name='add' value='Create' class='Buttons' id='add'>";    

In Javascript

function validate_create()
{
var bigimage = document.getElementById('bigimage');
var smallimage = document.getElementById('smallimage');

var big_img_width = bigimage.clientWidth;
var big_img_height = bigimage.clientHeight;

var small_img_width = smallimage.clientWidth;
var small_img_height = smallimage.clientHeight;

// if condtion to check the condition //
}

Here i am getting width and height for both images as same even i choose different size files.

How to do this? please suggest me

Thanks in advance

  • 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-03T07:15:15+00:00Added an answer on June 3, 2026 at 7:15 am

    When you execute bigimage.clientWidth or smallimage.clientWidth, you’re actually getting the width of the input elements, not the images that you’re about to upload. Also, your JavaScript is executed before the files are actually uploaded, and the resolution of the images is not known at this time. In fact, you don’t even know if the files are really image files.

    The type of an uploaded file, and the image resolution if it is an image, can only be determined after the upload has completed. This will therefore have to be done in PHP (your AppActions.php script). In PHP, you can access file $_FILES global to see which files were uploaded, their type, and their size. You can then open the images and use imagesx and imagesy to determine the dimensions.

    If you must know the file type before you permit the upload, then I believe your only way out is to use a flash component. For instance, SWFUploader. JavaScript can never access a file on the user’s computer, but Flash can and allows you to determine file type and size before actually uploading the file. Still, your site would then require Flash which may not be what you want.

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

Sidebar

Related Questions

I have a form that I upload two images. I want to do validation
i have a form which i want to be validated with javascript before submitting.
I have particular css through which I am hiding image. Now I want to
I want to upload a file using multipart form data and have problems with
I have use these code to upload two images in folder of the root
I want to validate a condition before doing the next step, but only raise
I want to validate a registration form that accepts an email address in the
I want validate a url that is a image e.g.: http://www.mydomain.com/image.jpg http://www.mydomain.com/image.png http://www.mydomain.com/image.jpeg http://www.mydomain.com/image.gif
I am using a HTML form to upload image files. Now i am using
I don't want to use Wordpress' built in media uploader. I have a form

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.