【问题标题】:UIKIT 3 get the name of the file been uploadedUIKIT 3 获取已上传文件的名称
【发布时间】:2018-09-10 01:57:11
【问题描述】:

我尝试创建一个函数,让用户上传文件,然后显示已上传到 div 的图像。但我需要有文件名才能将 src attr 添加到

似乎 UIKIT 3 在删除或选择文件时无法获取文件的名称。

有人可以帮忙吗?

这是来自 UIKIT 的代码,here 是他们提供的文档

               UIkit.upload('.js-upload', {

                    url: '../config/forms.php',

                    beforeSend: function () {
                        console.log('beforeSend', arguments);

                    },
                    beforeAll: function () {
                        console.log('beforeAll', arguments);
                    },
                    load: function () {
                        console.log('load', arguments);
                    },
                    error: function () {
                        console.log('error', arguments);
                    },
                    complete: function () {
                        console.log('complete', arguments);
                    },

                    loadStart: function (e) {
                        console.log('loadStart', arguments);

                        bar.removeAttribute('hidden');
                        bar.max = e.total;
                        bar.value = e.loaded;
                    },

                    progress: function (e) {
                        console.log('progress', arguments);

                        bar.max = e.total;
                        bar.value = e.loaded;
                    },

                    loadEnd: function (e) {
                        console.log('loadEnd', arguments);

                        bar.max = e.total;
                        bar.value = e.loaded;
                    },

                    completeAll: function (arguments) {

                        console.log('completeAll', arguments);

                        setTimeout(function () {
                            bar.setAttribute('hidden', 'hidden');
                        }, 1000);

                    }

                });

【问题讨论】:

标签: javascript php jquery uikit getuikit


【解决方案1】:

JS端:

                        UIkit.upload('.js-upload', {

                            url: 'file_upload.php',
                            multiple: false,
                            mime: "image/*",

                            completeAll: function () {
                                uploaded_filename = arguments[0].response;
                            }

                        });

PHP端:

$uploads_dir = PUBLIC_FOLDER."uploads"; 
$tmp_name = $_FILES['form-drop-place']['tmp_name'];
$image_name = $_FILES['form-drop-place']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$new_name = "newname." . $ext;
$new_place = $uploads_dir . "/" . $new_name;

if ( move_uploaded_file($tmp_name, $new_place) ) {
    die($new_name);
} else {
    die();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-28
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 2019-04-05
    • 2013-08-01
    相关资源
    最近更新 更多