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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP