douxian6086 2016-01-02 07:02
浏览 35

无法使用Angular.js和PHP测量文件大小

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作