无法在PHP中上传文件

Aza*_*han 2 php file-upload

大家好我想在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; */

}
Run Code Online (Sandbox Code Playgroud)

这段代码总是把我扔进其他条件.在我的html表单中我也添加了enctype="multipart/form-data"并且还检查了我的$ _FILES数组中的$ _FILES数组我得到了这个

数组([fileToUpload] =>数组([名称] => Book1.xlsx的副本[type] => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [tmp_name] => H:\ PHP\xampp\tmp\phpF54F .tmp [error] => 0 [size] => 13459))

Apb*_*Apb 6

在你的if条件中将其更改为 move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_path)

  • 在服务器上传文件时,它首先存储在临时位置,`move_uploaded_file`函数从临时位置获取文件并上传到给定的目标位置. (3认同)