首先,我使用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>
但是当我在这里的时候,我要做什么来保存我的文件?
我试着在flowFilename
和flowRelativePath
上做move_uploaded_file()
,但没有任何附加。
my new in js.
谢谢。
查看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'];
使用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();
}
}
我刚刚花了半天的时间与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>
,
它现在应该POST一个请求到"/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>
是
创建一个名为uploads的文件夹表示将临时文件移动到这里,然后在php脚本中添加代码。
$uploads_dir = 'uploads';
$target_file = $uploads_dir .'/'. basename($_FILES['file']['name']);
move_uploaded_file($_FILES['file']['tmp_name'],$target_file);