naren naren - 2 months ago 10
PHP Question

how to images uploaded multiple users in javascript

enter image description here
enter image description here


this is my screen shot,see user1 uploaded some files/images for example (image1,image2 and image3).Another user(user2) uploaded some files/images (image4,image5,image6).Both user uploading files/images at same time.I'm using single directory for users files uploaded directory.Now I'm facing which files/images which user uploaded it?this angular.js file


'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';

}
?>

Answer

According to the documentation, you can send some form data with your files (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'}]});
       //[...]
    }
Comments