Warm tip: This article is reproduced from serverfault.com, please click

javascript-使用filepond创建用于文件上传的PHP后端

(javascript - Creating PHP backend for file upload using filepond)

发布于 2020-12-21 21:53:00

我正在网站上创建表格,文件(图像和pdf)也需要上传。到目前为止,我只使用了一个简单input type="file"元素,将其与后端的PHP文件耦合(如下所示):

$allowed = array('jpg', 'jpeg', 'pdf', 'png');
if(isset($_FILES['uploadctl']) && $_FILES['uploadctl']['error'] == 0){
    $extension = pathinfo($_FILES['uploadctl']['name'], PATHINFO_EXTENSION);

    if(!in_array(strtolower($extension), $allowed)){
        echo '{"status":"not_allowed"}';
        exit;
    }

    // create folder to upload files to
    $id = session_id();
    $user_folder = 'user_data/' . $id;
    if( is_dir($user_folder) === false ){
        mkdir($user_folder); 
    }
    if(move_uploaded_file($_FILES['uploadctl']['tmp_name'], $user_folder . "/" . $_FILES['uploadctl']['name'])){
        echo '{"status":"success"}';
        exit;
    }
    echo '{"status":"error"}';
}

这很好。但是,我希望上传表单具有更多功能,并且已经研究了filepond我根据文档创建了filepond对象,并将样板代码复制到./file-pond-assets,我计划在以后适应我的需求:

<input type="file" name="uploadctl" multiple accept=".pdf,.png,.jpg,.jpeg">
<script>
            const inputElement = document.querySelector('input[type="file"]');
            const pond = FilePond.create( inputElement );
            pond.setOptions({
                server: './file-pond-assets'
            });
</script>

显示网站时显示的内容。尝试上传文件时,前端看起来不错,并upload complete显示一条消息。但是,我找不到在已上传的文件TMP上传文件夹内./file-pond-assets我尝试更改文件夹的权限,还检查了控制台,但找不到错误消息。的config.php文件也指向了正确的文件夹。我想念什么使我的文件不显示在服务器上?我想将上传内容保留为多部分/表单数据。

Questioner
Iridium
Viewed
0
Rilla 2021-05-16 01:39:31

这是gihtub回购链接上我的示例文件池PHP服务器实现存储库的链接:https : //github.com/Onihani/filepond-php-server-example 实时预览:http : //www.ics-courses.co .uk / natbongo / filepond-php-server-example /