I have one issue while i am uploading my file into local folder using Angular.js and PHP.I am explaining my code below.
<div ng-class="{'myError': billdata.regdoc.$touched && billdata.regdoc.$invalid }">
<input type="file" class="filestyle form-control" data-size="lg" name="regdoc" id="regdoc" ng-model="regfile" ngf-pattern="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" accept="application/pdf,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.wordprocessingml.document" ngf-select="onRegFileSelect($file);" >
</div>
My controller side code is given below.
$scope.onRegFileSelect=function(files){
//console.log('docs details',files);
regDocURL=files;
$scope.firstDocs='';
}
if($scope.firstDocs ==''){
var regDocs=regDocURL;
var curnum=(Math.random() * new Date().getTime()).toString(36).replace(/\./g, '');
newRegPath=curnum+"_"+ regDocs.name;
Upload.rename(regDocs, newRegPath);
var regdocsdata={'image':regDocs};
fileData.push(regdocsdata);
}else{
newRegPath=$scope.firstDocs;
}
console.log('file',fileData);
$scope.upload=Upload.upload({
url: 'php/uploadAll.php',
method:'POST',
file: fileData
}).success(function(data, status, headers, config) {
console.log('file succ',data);
}).error(function(data, status) {
console.log('file error',data);
});
uploadAll.php:
<?php
if(isset($_FILES['file'])){
// print_r($_FILES['file']);
for($i=0;$i<count($_FILES['file']['name']);$i++){
print_r($_FILES['file']['size'][$i]['image']);
/*$file_name = $_FILES['file']['name'][$i]['image'];
$file_size =$_FILES['file']['size'][$i]['image'];
$file_tmp =$_FILES['file']['tmp_name'][$i]['image'];
$file_type=$_FILES['file']['type'][$i]['image'];
$file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
$extensions = array("jpeg","jpg","png","pdf","ppt","docx");
if(in_array($file_ext,$extensions )=== false){
header("HTTP/1.0 401 Unauthorized");
$errors[]="image extension not allowed, please choose a JPEG or PNG file.";
print_r($errors);
return;
}
if($file_size > 2097152){
header("HTTP/1.0 401 Unauthorized");
$errors[]='File size cannot exceed 2 MB';
print_r($errors);
return;
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"../upload/".$file_name);
echo " uploaded file: " . "upload/" . $file_name.$file_size;
}else{
print_r($errors);
}*/
}
}else{
$errors= array();
header("HTTP/1.0 401 Unauthorized");
$errors[]="No file found";
print_r($errors);
}
?>
Here my problem is when i am uploading the big file lets say one file is more than 5/6 mb
the file size showing 0
so that i can not upload that file into folder but when i am uploading file related kb
the file size is easily measuring.another problem is when uploading big file its true that file is not uploading to the folder but this if(empty($errors)==true)
from above file is executing which should not.Here i need to calculate the file size and upload it accordingly.Please help me.