繁体   English   中英

如何使用Angular.js和PHP将多个文档上传到项目文件夹

[英]How to upload multiple documents into project folder using Angular.js and PHP

我需要使用Angular.js和PHP一次单击即可将不同类型的文档存储在项目文件夹中。 我在下面解释我的代码。

var fileData={'image':file,'regdoc':regDocs,'compRegDoc':compRegDocs};

$scope.upload=Upload.upload({
            url: 'php/uploadAll.php',
            method:'POST',
            file: fileData
    }).success(function(data, status, headers, config) {
            console.log('file',data);
    }).error(function(data, status) {
            console.log('err file',data);
    })

uploadALL.php:

<?php
if(isset($_FILES['file'])){    
    $errors= array();        
    $file_name = $_FILES['file']['name'];
    $file_size =$_FILES['file']['size'];
    $file_tmp =$_FILES['file']['tmp_name'];
    $file_type=$_FILES['file']['type'];   
    $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
    $extensions = array("jpeg","jpg","png");        
    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.";
    }
    if($file_size > 2097152){
        header("HTTP/1.0 401 Unauthorized");
        $errors[]='File size cannot exceed 2 MB';
    }               
    if(empty($errors)==true){
        //$today=('date')(new Date(),'yyyy-MM-dd HH:mm:ss');
        move_uploaded_file($file_tmp,"../upload/".$file_name);
        echo " uploaded file: " . "upload/" . $file_name;
    }else{
        print_r($errors);
    }
}
else{
    $errors= array();
    header("HTTP/1.0 401 Unauthorized");
    $errors[]="No image found";
    print_r($errors);
}
?>

在这里,我有一个图像,另外两个是.pdf / docx类型的文件。 当用户单击提交按钮时,这3个文件应存储在upload folder

//在php页面中使用此代码...用于上传所有文件

if(isset($_POST['submit'])!=""){
  $name=$_FILES['file']['name'];
  $size=$_FILES['file']['size'];
  $type=$_FILES['file']['type'];
  $temp=$_FILES['file']['tmp_name'];
  $caption1=$_POST['caption'];
  $link=$_POST['link'];
  move_uploaded_file($temp,"upload/".$name);

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM