Skip to content Skip to sidebar Skip to footer

AngularJS Image Upload Using Php

I've got a problem with an image upload in AngularJS. I found this question on here: Angularjs - File upload with php As in the other question I try to use https://github.com/dania

Solution 1:

I had a problem in my PHP. The problem was with the $_FILES['image'] image should have been file It should have been:

<?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){
         $errors[]="image extension not allowed, please choose a JPEG or PNG file.";
    }
    if($file_size > 2097152){
        $errors[]='File size cannot exceed 2 MB';
    }               
    if(empty($errors)==true){
        move_uploaded_file($file_tmp,"PlayerAvatar/".$file_name);
        echo " uploaded file: " . "images/" . $file_name;
    }else{
        print_r($errors);
    }
}
else{
    $errors= array();
    $errors[]="No image found";
    print_r($errors);
}
?>

Post a Comment for "AngularJS Image Upload Using Php"