未设置上传图片$ _FILES [英] upload image $_FILES is not set
本文介绍了未设置上传图片$ _FILES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将文件上传到我的服务器 但是问题是if(isset($ _ FILES ['upl'])))总是返回false
I'm trying to upload a file to my server But the problem is the if(isset($_FILES['upl'])) always returns false
我的php:
if($_SERVER['REQUEST_METHOD'] == 'POST')
$allowed = array('png', 'jpg', 'gif', 'jpeg', 'bmp');
{
if(isset($_FILES['upl']) )
{
echo 'test';
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo json_encode(array('success'=> false, 'message'=> 'No supported file type'));
exit;
}
$filename = "test".$extension;
if(move_uploaded_file($_FILES['upl']['tmp_name'], $url.'images/uploads/'.$filename)){
echo json_encode(array('success'=> true, 'url'=> $weburl .'images/uploads/'. $filename, 'filename' => $_FILES['upl']['name']));
exit;
}
}
}
html:
<form action="" method="post">
<label for="file">Logo</label><input type="file" name="upl">
<input type="submit" disabled='disabled' value=''>
</form>
如果进行页面内检查,我从不使用任何操作,但使用它不能解决问题
I never use an action if inpage check, using one doesn't fix the problem
推荐答案
您丢失了
enctype="multipart/form-data"
形式
<form action="" method="post" enctype="multipart/form-data">
这篇关于未设置上传图片$ _FILES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文