10

首先,我使用ng-flow(angular.js框架上的html5文件上传扩展)

我的文件已上传,我将事件记录在控制台中。但我不明白在哪里以及如何保存它们。

这是我的html代码,调用了上传。

<div flow-init flow-files-submitted="$flow.upload()">   
<div class="drop" flow-drop ng-class="dropClass">
    <span class="btn btn-default" flow-btn>Upload File</span>
    <span class="btn btn-default" flow-btn flow-directory ng-show="$flow.supportDirectory">Upload Folder</span>
    <b>OR</b>
    Drag And Drop your file here
</div>

这是我的配置

app.config(['flowFactoryProvider', function (flowFactoryProvider) {
  flowFactoryProvider.defaults = {
    target: 'upload.php',
    permanentErrors: [404, 500, 501],
    maxChunkRetries: 1,
    chunkRetryInterval: 5000,
    simultaneousUploads: 4,
    singleFile: true
  };
  flowFactoryProvider.on('catchAll', function (event) {
    console.log('catchAll', arguments);
  });
  // Can be used with different implementations of Flow.js
  // flowFactoryProvider.factory = fustyFlowFactory;
}]);

upload.php被调用,并且$_GET充满了数据,

<script>alert('alert' + array(8) {
  ["flowChunkNumber"]=>
  string(1) "1"
  ["flowChunkSize"]=>
  string(7) "1048576"
  ["flowCurrentChunkSize"]=>
  string(6) "807855"
  ["flowTotalSize"]=>
  string(6) "807855"
  ["flowIdentifier"]=>
  string(11) "807855-3png"
  ["flowFilename"]=>
  string(5) "3.png"
  ["flowRelativePath"]=>
  string(5) "3.png"
  ["flowTotalChunks"]=>
  string(1) "1"
}
)</script>

但是当我在这里时,我必须做些什么来保存我的文件?

我试着做move_uploaded_file()flowFilenameflowRelativePath没有任何附加。

我是js新手。

谢谢你。

4

4 回答 4

4

查看 upload.php 示例脚本:

https://github.com/flowjs/flow.js/blob/master/samples/Backend%20on%20PHP.md

// init the destination file (format <filename.ext>.part<#chunk>
// the file is stored in a temporary directory
$temp_dir = 'temp/'.$_POST['flowIdentifier'];
$dest_file = $temp_dir.'/'.$_POST['flowFilename'].'.part'.$_POST['flowChunkNumber'];
于 2014-07-03T08:15:25.827 回答
2

使用 flow.js 上传图片后,会向您的服务器发送一个新的发布请求。您需要处理此 POST 请求并在之后操作该文件。

如果您使用的是 Java + Spring MVC,它看起来像

@RequestMapping(value = "/upload",
        method = RequestMethod.POST,
        produces = MediaType.APPLICATION_JSON_VALUE)
public void handleFileUpload(@RequestParam("file") MultipartFile file) {
    log.debug("REST request to handleFileUpload");
    try {
        BufferedOutputStream stream =
                new BufferedOutputStream(new FileOutputStream(new File(path + file.getName())));
        stream.write(file.getBytes());
        stream.close();
        log.debug("You successfully uploaded " + file.getName() + "!");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
于 2015-05-23T09:35:52.513 回答
0

我刚刚花了半天时间使用 ng-flow,并想为 PHP 发布解决方案。它没有利用分块和恢复功能,我只需要无需刷新页面即可上传的内容。

一、flow-init="{target: '/upload', testChunks:false}" 例子

<div flow-init="{target: '/upload', testChunks:false}" flow-files-submitted="$flow.upload()" flow-file-success="$file.msg = $message">
            <input type="file" flow-btn />
            <span flow-btn>Upload File</span>
</div>

第二,

它现在应该向“/upload”发送一个请求.....在该请求中存在一个 $_FILES 数组。

一行代码为我保存了文件:

$result=move_uploaded_file($_FILES['file']['tmp_name'],'yourfilename');

如果您希望通过角度控制器来控制它,您可以像这样设置值:

    $scope.uploader={};
    $scope.upload = function (id) {

        $scope.uploader.flow.opts.testChunks=false;
        $scope.uploader.flow.opts.target='/upload;
        $scope.uploader.flow.upload();
    }

并在您的 html 中添加:

<div flow-init flow-name="uploader.flow">
<button flow-btn>Add files</button>
<div>

大学教师

于 2015-12-11T15:29:00.247 回答
0

创建一个名为uploads的文件夹意味着您将临时文件移动到此处,然后在 php 脚本中添加代码。

$uploads_dir = 'uploads';
$target_file = $uploads_dir .'/'. basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'],$target_file);
于 2016-06-15T01:24:33.003 回答