AngularJS [SOLVED]: How to upload image using angularjs php mysql

AngularJS [SOLVED]: How to upload image using angularjs php mysql

Home Forums Frameworks AngularJS tutorials AngularJS [SOLVED]: How to upload image using angularjs php mysql

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246145

    Cloudy Point
    Keymaster

    QuestionQuestion

    Is there any working angularjs, php, and/or mysql for uploading
    base 64 image file?

    Any answer will be appreciated.
    Thanks.

    #246146

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    Yes, You can upload any image or file using AngularJs follow the below steps.
    Note here I am uploading the file to store in a folder and not to the database because it’s a bad idea to upload the file into the database instead of that store the file into folder and name of the file in the database.

    Step 1: Create the simple view in HTML as below:

    <form name="upload_file" id="upload_file" ng-submit="functionName();">    
        <input type="file" name="inputfieldname">
        <button type="submit">Upload</button>
    </form>
    

    Now in angular controller write the function as below:

    $scope.functionName = function() {
     var formdata = new FormData();
     var filename = document.getElementById('upload_file').files[0];
    
     formdata.append('filename', filename);
    
        $http({
            method: 'post',
            url: 'action.php',//Put your php file url
            data: formdata,
            headers: {'Content-Type': undefined},
        }).then(function successCallback(result) {
    
            $scope.message = result.data;
            alert($scope.message);
    
        });
    }
    

    Source: https://stackoverflow.com/questions/47924192/how-to-upload-image-using-angularjs-php-mysql
    Author: shriram
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.