【问题标题】:How to upload multiple documents into project folder using Angular.js and PHP如何使用 Angular.js 和 PHP 将多个文档上传到项目文件夹
【发布时间】:2015-12-28 09:51:14
【问题描述】:

我需要使用 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);
    })

上传ALL.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 中。

【问题讨论】:

    标签: javascript php angularjs ng-file-upload


    【解决方案1】:

    // 在 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);
    
    }
    

    【讨论】:

    • @ NimeSH Patel:这是什么$caption1=$_POST['caption']; $link=$_POST['link'];,我在表单上没有提交功能。我正在使用点击事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多