Home > Web Front-end > JS Tutorial > Here is the article title: Can You Determine File Size Before Uploading with AJAX/PHP?

Here is the article title: Can You Determine File Size Before Uploading with AJAX/PHP?

Linda Hamilton
Release: 2024-10-30 20:23:02
Original
368 people have browsed it

以下是文章标题:

Can You Determine File Size Before Uploading with AJAX/PHP?

Determining File Size Before Upload

Want to know if you can find out the size of a file before uploading it? If using AJAX/PHP and in the change event of the input file, is there any way?

Answer

For the following HTML:

<code class="html"><input type="file" id="myFile" /></code>
Copy after login

Try this:

<code class="javascript">// 绑定到输入字段的 onchange 事件
$('#myFile').bind('change', function() {

  // this.files[0].size 获取文件的大小。
  alert(this.files[0].size);

});</code>
Copy after login

See the following thread:

How to check file input size with jQuery?

The above is the detailed content of Here is the article title: Can You Determine File Size Before Uploading with AJAX/PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template