<?php
//max size of about 2 mb
define('MAX_FILE_SIZE','2000000');//2 MB
$allowed_file_types=array('image/jpg','image/png','image/jpeg');
//var_dump($_FILES['file_to_upload']);
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['action'])){
if($_POST['action']=='upload_image'){
//if($_FILES['file_to_upload']['error']){
//}
if(isset($_FILES['file_to_upload'])){
$file_arr=$_FILES['file_to_upload'];
$check=false;
echo $file_arr['type'];
//for allowing image type only
foreach($allowed_file_types as $type){
if($file_arr['type']==$type){
$check=true;
}
}
if($check){
//checking size limit
if($file_arr['size']>MAX_FILE_SIZE){
echo "<p class='warning'>The file size is above limit. Optimize the image and upload again.</br>Your File Size:".round(($file_arr['size']/1000000),2)."MB<br/>Allowed File Size: ".round((MAX_FILE_SIZE/1000000),2)."MB</p>";
}else{
upload_form($file_arr);
}
}else{
echo "<p class='warning'>".$file_arr['type']." type of file is not allowed to upload</p>";
}
}
}
}
}
我正在使用此代码获取有关要从表单上传的文件的信息。基本上发生的是当我选择一个大于2.7 / 3 mb的文件时,我在$ _FILES上使用的var_dump返回null。这适用于小于该大小的所有其他文件。我从$ _FILES获得了正确的数组。是什么导致这种情况发生?有什么建议吗?
BTW php.ini max_upload_size == 65M