如何通过HTML表单将文件发送到$ _FILE?

时间:2019-05-03 17:52:14

标签: php html web web-development-server

一个非常简单的问题。但是由于某些原因无法正确解决问题。

向其发送文件的html代码是什么?

move_uploaded_file($FILES["upload"]["tmpname"], $_POST["name"]);

这是我的,但是当我使用它并回显/ vardump一切时,我只有“名称”而不是文件

<form action="uploader.php" method="post" id="myForm" enctype="multipart/form-data">
    Select file to upload:
    <input type="file" name="upload" id="upload">
    <input type="text" name="name" id="name">
    <button name="submit" class="btn btn-primary" type="submit" value="submit">Upload File</button>

 </form>

谢谢

1 个答案:

答案 0 :(得分:0)

我尝试添加评论,但我不能

首先检查php.ini中是否启用了上传权限

file_uploads = On

如果将其设置为on,请检查您在uploader.php文件中添加的上载目录,并使用是否检查$ _FILES ['upload']为空 这是uploader.php文件的简单代码

    <?php
    if(!empty($_FILES['upload'])) 
    {
        $path = "upload/"; /// directory to upload 
        $path = $path . basename( $_FILES['upload']['name']);
        if(move_uploaded_file($_FILES['upload']['tmp_name'], $path)) {
            echo "The file ".  basename( $_FILES['upload']['name']).
                " has been uploaded";
        } else{
            echo "There was an error uploading the file, please try again!";
        }
    }else {
    echo 'No file selected to upload ';
}