1

I am a beginner in making a web page using HTML, JavaScript, and PHP. I am now working on a web page for the user to upload an image with a specific dimension and extension because of my code was written before and can be used only in particular requirements.

The code for uploading the image is as follows:

<form name="images" method="POST" action="send.php">
<label>Some text</label>
<input type="text" name="someText"/>
<label>The image: </label>
<input id="img" type="file" name="imageUpload" accept=".jpg"/><br/>
<input type="submit" value="submit"/>
</form>

I have search through the Internet and tried a number of solutions provided, but I could not solve the problem. Are there any other ways to deal with the problem. Thank you very much!

The solution I have tried: http://blog.xuite.net/mark.wu/x/49421803-上傳檔案前,JavaScript檢查檔案格式、大小+ https://zhidao.baidu.com/question/488777030449774252.html

1 Answers1

0

Try following code

var _URL = window.URL || window.webkitURL;

$("#img").change(function(e) {
  var file, img;
  if ((file = this.files[0])) {
    img = new Image();
    img.onload = function() {
      console.log("width : " + this.width + " height : " + this.height);
    };
    img.src = _URL.createObjectURL(file);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<input id="img" type="file" name="imageUpload" /><br/>
Nisal Edu
  • 7,237
  • 4
  • 28
  • 34