简体   繁体   English

如何使用 PHP 在 dropzone.js 中上传文件

[英]How to upload file in dropzone.js with PHP

So I have a dropzone upload file parameter and I want to send that file to PHP so I can upload it to the database.所以我有一个 dropzone 上传文件参数,我想将该文件发送到 PHP,以便我可以将其上传到数据库。 I have a post parameter already for that file我已经有该文件的 post 参数

$_POST['filetest']

And the form和形式

<form id="recruit_form" action="<?php echo current_url(); ?>" method="post" enctype="multipart/form-data">

<input type="text" id="name" class="form-input " name="name"
                           placeholder="<?php echo translate('name'); ?>" required>
                </div>

<input type="text" id="email" class="form-input " name="email"
                           placeholder="Email" required>
                </div>

 <div id="dropzone"></div>

</form>

So how do I get the file in PHP with the name of the post I assigned (filetest).那么如何使用我分配的帖子名称(filetest)在 PHP 中获取文件。 Cause now, it doesn't have any name.因为现在,它没有任何名字。 The others work just fine, i tried adding name="filetest", but with no success, the only input that gives an error is this one.其他人工作得很好,我尝试添加 name="filetest",但没有成功,唯一出现错误的输入是这个。

Please use the input file field in the HTML form like <input type="file" name="filetest" >请使用 HTML 表单中的输入文件字段,例如<input type="file" name="filetest" >

if (move_uploaded_file($_FILES["filetest"]["tmp_name"], 'Target file with path')) {
        echo "The file ". basename( $_FILES["filetest"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }

Hope this will help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM