douzhan1963 2014-12-29 04:05
浏览 55
已采纳

变量存储错误数据

I am trying to display whatever is stored in a variable depending on what the user does, if they upload a photo then it is stored in the $SellPhoto2 variable but if they dont "defaultcar.jpg" is stored in the variable, here is what I have so far:

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);

This is the var_dump:

string(14) "defaultcar.jpg"

When I upload a file it displays "defaultcar.jpg" when it should actually display the uploaded file, does anyone understand what I am doing wrong?

  • 写回答

1条回答 默认 最新

  • donglei3370 2014-12-29 04:13
    关注

    from documentation:

    For proper working, the function is_uploaded_file() needs an argument like $_FILES['userfile']['tmp_name'], - the name of the uploaded file on the client's machine $_FILES['userfile']['name'] does not work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料