无法上传PHP中的文件
大家好,我试图上传文件在PHP中。 但它没有上传文件
这是代码
$excel = new PhpExcelReader;
if(isset($_POST["submit"]))
{
$target_dir="../upload/";
$target_path=$target_dir.basename($_FILES['fileToUpload']['name']);
//move_uploaded_file($_FILES['fileToUpload']['name'],$target_path);
if(move_uploaded_file($_FILES['fileToUpload']['name'],$target_path))
{
echo basename($_FILES['fileToUpload']['name']);
}
else
{
echo "Possible file upload attack!n";
}
print_r($_FILES);
/* $handle = realpath($_FILES["fileToUpload"]["name"]);
$excel = new PhpExcelReader;
$excel->read($handle);
echo $handle; */
}
这段代码总是让我处于其他状态。在我的html表单中,我还添加了enctype="multipart/form-data"
,同时检查$ _FILES数组中的$ _FILES数组
Array([fileToUpload] => Array([name] => Copy1.xlsx [type] => application / vnd.openxmlformats-officedocument.spreadsheetml.sheet [tmp_name] => H: PHP xampp tmp phpF54F .tmp [error] => 0 [size] => 13459))
在您的if条件move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_path)
其更改为move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_path)
尝试这个。
if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_path))
{
echo basename($_FILES['fileToUpload']['name']);
} else {
echo "Possible file upload attack!n";
}
链接地址: http://www.djcxy.com/p/45503.html