2

我正在尝试为我的网站构建图像上传,我只有以下内容,根本没有输出,但我的页面渲染还好吗?谁能看到我哪里出错了?\

    //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>
4

1 回答 1

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出来,所以你没有收到任何消息。

所以,很明显,我建议附和它。

于 2013-06-03T22:07:37.257 回答