这是我的屏幕截图,看到user1上传了一些文件/图像,例如(image1,image2和image3)。另一个用户(user2)上传了一些文件/图像(image4,image5,image6)。用户上传文件/图像同时我用单个目录为用户上传的文件目录。现在我面对用户上传的文件/图片吗?这个angular.js文件
'use strict';
$(function(){
$(document).on('click','#drop_div',function(){
$('#file_upload').click();
});
});
angular.module('app', ['angularFileUpload']).controller('AppController', ['$scope', 'FileUploader', function($scope, FileUploader) {
var uploader = $scope.uploader = new FileUploader({url: 'upload.php'});
console.log('uploader---------'+uploader);
uploader.filters.push({
name: 'customFilter',
fn: function(item /*{File|FileLikeObject}*/, options) {
var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
var file_exten_val = '|pdf|jpg|jpeg|png|bmp|gif|application|x-zip-compressed|'.indexOf(type);
var file_name = item.name;
var slice_exten = file_name.split('.');
console.log([type,file_exten_val]);
if((file_exten_val == -1) && (slice_exten[1] =='epub') || (type =='x-zip-compressed')){
return this.queue.length < 20;
}else if(file_exten_val >= 0){
return this.queue.length < 20;
}
}
});
}]);
upload.php的
<?php
if ( !empty( $_FILES ) ) {
$tempPath = $_FILES['file']['tmp_name'];
$uploadPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $_FILES[ 'file' ][ 'name' ];
echo $uploadPath;
move_uploaded_file( $tempPath, $uploadPath );
$answer = array( 'answer' => 'File transfer completed' );
$json = json_encode( $answer );
echo $json;
} else {
echo 'No files';
}
?>
答案 0 :(得分:0)
根据documentation,您可以使用您的文件发送一些表单数据(param formData ):
'use strict';
$(function(){
$(document).on('click','#drop_div',function(){
$('#file_upload').click();
});
});
angular.module('app', ['angularFileUpload']).controller('AppController', ['$scope', 'FileUploader', function($scope, FileUploader) {
var uploader = $scope.uploader = new FileUploader({url: 'upload.php', formData: [{username: 'MyUsername'}]});
//[...]
}