首先,我使用了ng-flow ( angular.js框架上的html5文件上传扩展)
我的文件已上传,我将事件记录在控制台中。但我不知道该把它们保存在哪里以及如何保存。
这是我的html代码,名为upload。
<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>但是当我在这里的时候,我必须做些什么来保存我的文件呢?
我试着在flowFilename和flowRelativePath上做move_uploaded_file(),但是没有附加任何东西。
我是js的新手。
谢谢。
发布于 2014-07-03 16:15:26
看看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'];发布于 2015-05-23 17:35:53
使用flow.js上传图像后,会向您的服务器发送一个新的post请求。您需要处理此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-12-11 23:29:00
我刚刚花了半天的时间使用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>完成
https://stackoverflow.com/questions/23811678
复制相似问题