PHP无法从HTML表单中获取文件

时间:2018-02-13 10:21:49

标签: php html

我无法将图像从HTML表单传递给PHP,以便将其上传到我的服务器上,这里是PHP代码

if($_SERVER["REQUEST_METHOD"] == "POST") {
include_once('config.php'); //db configuration
if (isset($_FILES['image'])){
    echo "I have the image";
}
else{
    echo "Image not loaded";
}}

以下是html表单:

<form method="post" action="edit_profile.php">
<div class="form-group">
<div class="form-group mb-30">
    <label class="control-label mb-10 text-left">Edit profile image</label>
    <div class="fileinput fileinput-new input-group" data-provides="fileinput">
        <div class="form-control" data-trigger="fileinput"> <i class="glyphicon glyphicon-file fileinput-exists"></i> <span class="fileinput-filename"></span></div>
        <span class="input-group-addon fileupload btn btn-info btn-anim btn-file"><i class="fa fa-upload"></i> <span class="fileinput-new btn-text">Select file</span> <span class="fileinput-exists btn-text">Edit</span>
        <input type="file" accept=".gif,.jpg,.jpeg,.png" name="image" /> <!-- INPUT ELEMENT -->
        </span> <a href="#" class="input-group-addon btn btn-danger btn-anim fileinput-exists" data-dismiss="fileinput"><i class="fa fa-trash"></i><span class="btn-text">Remove</span></a> 
    </div>
    <button type="submit" class="btn btn-success btn-anim" id="submitInfo"><i class="icon-rocket"></i><span class="btn-text">Confirm</span></button>
</div>

我已经检查过“&#39; name&#39; "<input type="file" />的属性以及配置文件php.ini,我无法找出问题所在。

1 个答案:

答案 0 :(得分:1)

在表单中指定类似

的ctype
<form method="post" action="edit_profile.php" enctype="multipart/form-data">