无法在PHP中上传文件 [英] Unable to Upload file in PHP

查看:131
本文介绍了无法在PHP中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试用php上传文件.但这不是上传文件

Hi all I am trying to upload file in php. But it is not uploading the file

这是代码

$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数组,我得到了这个

This code always throw me in else condition.In my html form I also added enctype="multipart/form-data" and also check $_FILES array in my $_FILES array I am getting this

Array([fileToUpload] => Array([name] => Book1.xlsx [type]的副本 => application/vnd.openxmlformats-officedocument.spreadsheetml.sheet [tmp_name] => H:\ PHP \ xampp \ tmp \ phpF54F.tmp [错误] => 0 [大小] => 13459))

Array ( [fileToUpload] => Array ( [name] => Copy of Book1.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)

In your if condition change it to move_uploaded_file($_FILES['fileToUpload']['tmp_name'],$target_path)

这篇关于无法在PHP中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆