文件上传文件出错为空?为啥?
头部也写了
enctype="multipart/form-data"
——————————————————
——————————————————
public function postFile(){
$time=date('Y-d-m',time());
$uploaddir = '/public/Uploads/file';
$uploadfile = $uploaddir . basename(@$_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file(@$_FILES['userfile']['tmp_name'], $uploadfile)){
echo "Ok";
echo "Upload: " . @$_FILES["userfile"]["name"] . "<br />";
echo "Type: " . @$_FILES["file"]["type"] . "<br />";
echo "Size: " . (@$_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: ". @$_FILES["file"]["tmp_name"].$time;
} else {
return json_encode([]);
}
print_r(@$_FILES);
print "</pre>";
}
enctype="multipart/form-data"
——————————————————
POST提交的
<input type="file" name="userfile">——————————————————
public function postFile(){
$time=date('Y-d-m',time());
$uploaddir = '/public/Uploads/file';
$uploadfile = $uploaddir . basename(@$_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file(@$_FILES['userfile']['tmp_name'], $uploadfile)){
echo "Ok";
echo "Upload: " . @$_FILES["userfile"]["name"] . "<br />";
echo "Type: " . @$_FILES["file"]["type"] . "<br />";
echo "Size: " . (@$_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: ". @$_FILES["file"]["tmp_name"].$time;
} else {
return json_encode([]);
}
print_r(@$_FILES);
print "</pre>";
}
3 个回复
raisinli
赞同来自:
你检查一下你的目录权限,在主文件夹下: Public/Uploads/file 这个目录是否存在,注意大小写,WINDOWS主机不需要注意。
stupiddoggy
赞同来自:
未育龙年各类
赞同来自: