1 回答
TA贡献1780条经验 获得超5个赞
您也可以jquery在提交之前使用它来做样品:
<form action="upload" enctype="multipart/form-data" method="post">
Upload image:
<input id="image-file" type="file" name="file" />
<input type="submit" value="Upload" />
<script type="text/javascript">
$('#image-file').bind('change', function() {
alert('This file size is: ' + this.files[0].size/1024/1024 + "MB");
});
</script>
</form>
使用 PHP:
if (isset ( $_FILES['file'] ) ) {
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
if (($file_size > 50*1024*1024)){
$message = 'File too large. File must be less than 50 MB.';
echo '<script type="text/javascript">alert("'.$message.'");</script>';
}
}
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报