$ _FILES ['相片'];是空的

时间:2014-11-15 14:41:57

标签: php upload

我试图制作一个图片上传脚本但是$ _files ['photo'];一直都是空的。

$_FILES['photo']['name'];
$_FILES['photo']['size'];
$_FILES['photo']['type'];
$_FILES['photo']['tmp_name'];
$_FILES['photo']['error'];

当我回应它们时,它们都没有任何回报。

if($_FILES['photo']['name'])
{

if(!$_FILES['photo']['error'])
{
    $new_file_name = strtolower($_FILES['photo']['name']); 
    if($_FILES['photo']['size'] > (1024000)) 
    {
        $valid_file = false;
        $msg = 'Oops!  Your file\'s size is to large.';
        echo $msg;
    }

    if($valid_file)
    {
        move_uploaded_file($_FILES['photo']['tmp_name'], 'images/thumbnails/'.$new_file_name);
        $msg = 'Congratulations!  Your file was accepted.';
        echo $msg;
    }
}

else
{
    $msg = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
    echo $msg;
}
}

我做错了吗?

<form action='?p=post' method='POST'>
            <input type='file' name='photo' size='25' />
            <input type='submit' value='Posten' name='submit' /><br />
            </form>

1 个答案:

答案 0 :(得分:2)

您的表单缺少重要部分=&gt; enctype="multipart/form-data"将其添加到您的表单中。

<form action='?p=post' method='POST' enctype='multipart/form-data'>
  • 上传文件时需要数据编码类型。

请教: