1

我正在使用http://resumablejs.com/并且无法理解如何在上传后更改文件名。

再描述一下我的情况:

我有带有默认代码的文件 UploadFile.php:

include 'vendor/autoload.php';

use Dilab\Network\SimpleRequest;
use Dilab\Network\SimpleResponse;
use Dilab\Resumable;

$request = new SimpleRequest();
$response = new SimpleResponse();

$resumable = new Resumable($request, $response);
$resumable->tempFolder = 'tmps';
$resumable->uploadFolder = 'upload/video';

$resumable->process();

我知道如果我将使用以下内容:

$originalName = $resumable->getOriginalFilename(Resumable::WITHOUT_EXTENSION);
$slugifiedname = 'custom_prefix_'.$originalName;
$resumable->setFilename($slugifiedname);

它会将“custom_prefix_”添加到我的文件名中。但!我需要使用表单中的一些附加信息(名字和姓氏)作为前缀,如何将此信息添加到我的请求中?

在前端我的文件看起来像:

<script type="text/javascript">
        window.onload = (function () {
            var r = new Resumable({
                target: '/UploadFile.php',
                maxChunkRetries: 2,
                maxFiles: 1,
                prioritizeFirstAndLastChunk: true,
                simultaneousUploads: 4,
                chunkSize: 5 * 1024 * 1024,
                uploadMethod: 'POST',
                maxFileSize: 550 * 1024 * 1024
            });

...

    uploadFile.on('click', function () {
        $('.valid').html('');
        if (results.children().length > 0) {
            $.ajax({
                url: '/Validate.php',
                type: "POST",
                data: $('#upload_form').serialize()+'&fileType='+fType+'&fileName='+fName,
                dataType: "json",
                success: function (data) {
                    if (results.children().length > 0) {
                        if(data[0]==true && data[1]==true){
                            $.ajax({
                                url: '/FormUpload.php',
                                type: "POST",
                                data: $('#upload_form').serialize()+'&fileType='+fType+'&fileName='+fName,
                                success: function (data) {
                                    if (results.children().length > 0) {
                                        r.upload();
                                    } else {
                                        nothingToUpload.fadeIn();
                                        setTimeout(function () {
                                            nothingToUpload.fadeOut();
                                        }, 3000);
                                    }
                                }
                            });
                        }else{
                            if(data[0]==false){
                                valid.text('Please complete all required fields!');
                            }
                            if(data[1]==false){
                                valid.text('Please complete all exeption fields!');
                            }
                        }

                    } else {
                        nothingToUpload.fadeIn();
                        setTimeout(function () {
                            nothingToUpload.fadeOut();
                        }, 3000);
                    }
                }
            });
        } else {
            nothingToUpload.css('opacity', 1);
            setTimeout(function () {
                nothingToUpload.css('opacity', 0);
            }, 3000);
        }
    });
4

2 回答 2

0

试试这个代码:

$resumable->process();

// you can get file information after the upload is complete
if (true === $resumable->isUploadComplete()) { // true when the final file has been uploaded and chunks reunited.
    $extension = $resumable->getExtension();
    $filename = $resumable->getFilename();
}
于 2016-12-23T07:06:45.447 回答
0

我在我的文件 FormUpload.php 中找到了解决方案,我返回必要的信息并将其发送如下:

uploadFile.on('click', function () {
    $('.valid').html('');
    if (results.children().length > 0) {
        $.ajax({
            url: '/Validate.php',
            type: "POST",
            data: $('#upload_form').serialize()+'&fileType='+fType+'&fileName='+fName,
            dataType: "json",
            success: function (data) {
                if (results.children().length > 0) {
                    if(data[0]==true && data[1]==true){
                        $.ajax({
                            url: '/FormUpload.php',
                            type: "POST",
                            data: $('#upload_form').serialize()+'&fileType='+fType+'&fileName='+fName,

                            success: function (data) {
                                var data = jQuery.parseJSON(data);
                                if (results.children().length > 0) {
                                   r.files[0].fileName = data.new_file_name;
                                   r.upload();
                                } else {
                                    nothingToUpload.fadeIn();
                                    setTimeout(function () {
                                        nothingToUpload.fadeOut();
                                    }, 3000);
                                }
                            }
                        });
                    }else{
                        if(data[0]==false){
                            valid.text('Please complete all required fields!');
                        }
                        if(data[1]==false){
                            valid.text('Please complete all exeption fields!');
                        }
                    }

                } else {
                    nothingToUpload.fadeIn();
                    setTimeout(function () {
                        nothingToUpload.fadeOut();
                    }, 3000);
                }
            }
        });
    } else {
        nothingToUpload.css('opacity', 1);
        setTimeout(function () {
            nothingToUpload.css('opacity', 0);
        }, 3000);
    }
});
于 2016-12-23T22:46:30.123 回答