变量存储错误数据

时间:2014-12-29 04:05:19

标签: php variables file-upload

我试图显示存储在变量中的内容,具体取决于用户的操作,如果他们上传了一张照片,那么它会存储在$ SellPhoto2变量中,但如果他们不将“defaultcar.jpg”存储在变量中,这是我到目前为止:

if(is_uploaded_file($_FILES["SellPhoto2"]['name']))
    {
        if ($CheckFileType2 != "jpg") 
        {
            echo '<div class="alert alert-danger">' . "You are trying to upload a " . pathinfo($_FILES['SellPhoto2']['type'], PATHINFO_EXTENSION) . " file, the file must be either .jpg." . '</div>';
        }

        if (file_exists('images/' . $_SESSION["info"]["id"] . '/' . $_FILES['SellPhoto2']['name'])) 
        {
            echo '<div class="alert alert-danger">The file name you are trying to upload as your second photo already exists, please rename your file.</div>';
        }

        $SellPhoto2 = $_FILES['SellPhoto2']['name'];
     }
    else
    {
        $SellPhoto2 = "defaultcar.jpg";
    }

var_dump($SellPhoto2);

这是var_dump:

string(14) "defaultcar.jpg"

当我上传文件时,它显示“defaultcar.jpg”,当它实际显示上传的文件时,是否有人理解我做错了什么?

1 个答案:

答案 0 :(得分:1)

来自documentation

  

为了正常工作,函数is_uploaded_file()需要一个参数   比如$ _FILES [&#39; userfile&#39;] [&#39; tmp_name &#39;], - 上传文件的名称   在客户端的计算机上$ _FILES [&#39;用户文件&#39;] [&#39;名称&#39;]不起作用