Tải lên phía khách hàng Hủy bỏ
Trên các trình duyệt hiện đại (FF> = 3.6, Chrome> = 19.0, Opera> = 12.0 và Buggy trên Safari), bạn có thể sử dụng API tệp HTML5. Khi giá trị của đầu vào tệp thay đổi, API này sẽ cho phép bạn kiểm tra xem kích thước tệp có nằm trong yêu cầu của bạn hay không. Tất nhiên, điều này, cũng như MAX_FILE_SIZE, có thể bị giả mạo vì vậy luôn luôn sử dụng xác thực phía máy chủ.
<form method="post" enctype="multipart/form-data" action="upload.php"> <input type="file" name="file" id="file" /> <input type="submit" name="submit" value="Submit" /> </form> <script> document.forms[0].addEventListener('submit', function( evt ) { var file = document.getElementById('file').files[0]; if(file && file.size < 10485760) { // 10 MB (this size is in bytes) //Submit form } else { //Prevent default and display error evt.preventDefault(); } }, false); </script>Tải lên phía máy chủ Hủy bỏ
Về phía máy chủ, không thể dừng tải lên xảy ra từ PHP vì một khi PHP đã được gọi, tải lên đã hoàn thành. Nếu bạn đang cố gắng lưu băng thông, bạn có thể từ chối tải lên từ phía máy chủ với cài đặt INI upload_max_filesize. Rắc rối với điều này là điều này áp dụng cho tất cả các tải lên, vì vậy bạn sẽ phải chọn một cái gì đó tự do hoạt động cho tất cả các tải lên của bạn. Việc sử dụng MAX_FILE_SIZE đã được thảo luận trong các câu trả lời khác. Tôi đề nghị đọc hướng dẫn trên đó. Có biết rằng nó, cùng với bất cứ điều gì khác về phía máy khách (bao gồm cả kiểm tra JavaScript), có thể bị giả mạo để bạn phải luôn luôn có xác thực phía máy chủ (PHP).
Xác thực PHP
Về phía máy chủ, bạn nên xác nhận rằng tệp nằm trong các hạn chế kích thước (vì mọi thứ cho đến thời điểm này ngoại trừ cài đặt INI có thể bị giả mạo). Bạn có thể sử dụng mảng $_FILES để tìm ra kích thước tải lên. (Tài liệu về nội dung của $_FILES có thể được tìm thấy bên dưới các tài liệu MAX_FILE_SIZE)
upload.php
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } }Chắc chắn ¶ ¶
8 năm trước
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.
Example:
<?php
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 0
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 1Steve Dot Criddle tại CRD Sector Dot Com ¶ ¶
18 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 2
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 3
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 4
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 5
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6AM tại netactor dot no_span dot com ¶ ¶
20 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 7
svenr tại selfhtml dot org ¶ ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 8
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 9
MAX_FILE_SIZE0
MAX_FILE_SIZE1
MAX_FILE_SIZE2
MAX_FILE_SIZE3
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6~ Caetin ~ (at) ~ hotpop ~ (dot) ~ com ~ ¶ ¶
18 năm trước
MAX_FILE_SIZE5
MAX_FILE_SIZE6
MAX_FILE_SIZE7
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6AM tại netactor dot no_span dot com ¶ ¶
20 năm trước
MAX_FILE_SIZE9
upload_max_filesize0
upload_max_filesize1
upload_max_filesize2
upload_max_filesize3
upload_max_filesize4
upload_max_filesize5
upload_max_filesize6
upload_max_filesize7
upload_max_filesize8
upload_max_filesize9
MAX_FILE_SIZE0
MAX_FILE_SIZE1
MAX_FILE_SIZE2
MAX_FILE_SIZE3
MAX_FILE_SIZE4
MAX_FILE_SIZE5
MAX_FILE_SIZE6
MAX_FILE_SIZE7
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Keith tại phpdiary dot org ¶ ¶
17 năm trước
MAX_FILE_SIZE9
$_FILES0
$_FILES1
$_FILES2
$_FILES3
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6CEO tại L-i-e Dot Com ¶ ¶
17 năm trước
$_FILES5
$_FILES6
$_FILES7
$_FILES8
$_FILES9
$_FILES0
$_FILES1
$_FILES2
$_FILES3
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6CEO tại L-i-e Dot Com ¶ ¶
17 năm trước
$_FILES5
CEO tại L-i-e Dot Com ¶ ¶
Myko tại Blue Kim Dot Com ¶
$_FILES6
$_FILES7
$_FILES8
$_FILES9Thông tin tại Levaravel Dot Com ¶ ¶
13 năm trước
MAX_FILE_SIZE0
MAX_FILE_SIZE1
MAX_FILE_SIZE2
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Jan tại Lanteraudio Dot NL ¶ ¶
9 năm trước
MAX_FILE_SIZE4
MAX_FILE_SIZE5
MAX_FILE_SIZE6
MAX_FILE_SIZE7
MAX_FILE_SIZE8
MAX_FILE_SIZE9
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.0
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.1
jedi_aka tại yahoo dot com ¶ ¶
15 năm trước
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.3
Cướp ¶ ¶
Myko tại Blue Kim Dot Com ¶
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.4
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.5
Thông tin tại Levaravel Dot Com ¶ ¶
13 năm trước
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.7
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.8
You'd better check $_FILES structure and values throughly.
The following code cannot cause any errors absolutely.9
Example:
<?php0
Example:
<?php1
Example:
<?php2
Jan tại Lanteraudio Dot NL ¶ ¶
Myko tại Blue Kim Dot Com ¶
Example:
<?php4
Example:
<?php5
Example:
<?php6
Thông tin tại Levaravel Dot Com ¶ ¶
17 năm trước
Example:
<?php8
13 năm trước ¶
17 năm trước
Example:
<?php9
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 00
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 01
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 02
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 03
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 04
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 05
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 06
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 07
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Jan tại Lanteraudio Dot NL ¶ ¶
9 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 09
jedi_aka tại yahoo dot com ¶ ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 10
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 11
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 12
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 13
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 14
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Cướp ¶ ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 16
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 17
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 18
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 19
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 20Cướp ¶ ¶
17 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 21
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 22
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 23
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 24
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 614 năm trước ¶
9 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 26
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 27
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 28
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6jedi_aka tại yahoo dot com ¶ ¶
17 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 30
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 31
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 615 năm trước ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 33
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 34
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 35
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 36
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Cướp ¶ ¶
17 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 38
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 39
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 40
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 41
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 614 năm trước ¶
9 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 43
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 44
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 45
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 46
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6jedi_aka tại yahoo dot com ¶ ¶
Myko tại Blue Kim Dot Com ¶
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 48
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 49
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 50
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 51
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 52
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6Thông tin tại Levaravel Dot Com ¶ ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 54
Cướp ¶ ¶
14 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 55
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 56
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 57
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 58Damien từ Valex ¶ ¶
9 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 59
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 60
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 61
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 62
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 63
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 64
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 65
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 66
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 67
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 68
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6jedi_aka tại yahoo dot com ¶ ¶
15 năm trước
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 70
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 71
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 72
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 73
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 74
<?php if(isset($_FILES['file'])) { if($_FILES['file']['size'] > 10485760) { //10 MB (size is also in bytes) // File too big } else { // File within size restrictions } } 6