Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I need to store different types of documents inside the project folder in single button click using Angular.js and PHP. I am explaining my code below.

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);
}
?>

Here I have one image and the other two are .pdf/docx type files. When the user clicks the submit button these 3 files should be stored inside upload folder.

share|improve this question

// use this code in php page... it's used to upload all file

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);

}
share|improve this answer
    
@ NimeSH Patel : what is this $caption1=$_POST['caption']; $link=$_POST['link']; and i dont have submit function on the form.I am using click event. – satya Dec 28 '15 at 9:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.