当前位置: 动力学知识库 > 问答 > 编程问答 >

php - $_files['photo']; is empty

问题描述:

I was trying to make an image upload script but $_files['photo']; is empty all the way.

$_FILES['photo']['name'];

$_FILES['photo']['size'];

$_FILES['photo']['type'];

$_FILES['photo']['tmp_name'];

$_FILES['photo']['error'];

When I echo them out, they all return absolutely nothing.

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;

}

}

Did I do something wrong maybe?

<form action='?p=post' method='POST'>

<input type='file' name='photo' size='25' />

<input type='submit' value='Posten' name='submit' /><br />

</form>

网友答案:

Your form is missing an essential part => enctype="multipart/form-data" add it in your form.

<form action='?p=post' method='POST' enctype='multipart/form-data'>
  • The data encoding type is required when uploading files.

Consult:

  • http://php.net/manual/en/features.file-upload.post-method.php
分享给朋友:
您可能感兴趣的文章:
随机阅读: