PHP文件上传不起作用,注意输出到浏览器

时间:2013-06-03 22:00:37

标签: php mysql pdo

我正在尝试为我的网站构建图片上传,我有以下内容,根本没有输出任何内容,但我的页面渲染没问题?任何人都可以看到我可能出错的地方吗?\

    //if they DID upload a file...
if($_FILES['profile_image']['name'])
{
    //if no errors...
    if(!$_FILES['profile_image']['error'])
    {
        //now is the time to modify the future file name and validate the file
        $new_file_name = strtolower($_FILES['profile_image']['tmp_name']); //rename file
        if($_FILES['profile_image']['size'] > (1024000)) //can't be larger than 1 MB
        {
            $valid_file = false;
            $message = 'Oops!  Your file\'s size is to large.';
        }

        //if the file has passed the test
        if($valid_file)
        {
            //move it to where we want it to be
            move_uploaded_file($_FILES['profile_image']['tmp_name'], 'uploads/'.$new_file_name);
            $message = 'Congratulations!  Your file was accepted.';
        }
    }
    //if there is an error...
    else
    {
        //set that to be the returned message
        $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['profile_image']['error'];
    }
}

else {
echo    'success';
    }

<form method="post" action="./process-signup.php" enctype="multipart/form-data" >


    <input type="file" class="profile_image text-input" name="profile_image" placeholder="Upload a picture"/><br />
    <input type="submit" id="signup-com-btn" value="Complete Signup" />

</form>

1 个答案:

答案 0 :(得分:1)

在PHP脚本中,您已将变量$message分配给不同阶段的不同值,如下所示:

 $message = 'Oops!  Your file\'s size is to large.';
 $message = 'Congratulations!  Your file was accepted.';   
 $message = 'Ooops!  Your upload triggered the following error:  

但是 实际上echoing它已经消失了,所以你没有收到任何消息。

显然,我建议回应它。