How to upload base64 file in PHP

9
15



Uploading files or images from mobile app is a most common case in many projects, there are two ways to finish this task, one of them is most popular, much safer, and considering as a best practice, which is encoding the uploaded file as a base64 string in your mobile application and send it as a normal post to the PHP API.

Java, objective c, c# and also Javascript has an option to encode files to base64 strings before sending it to the server

In this tutorial we will create a simple API to upload base64 encoded files or images to PHP server and also you will learn:

1-How to decode any file from base64?
2-How to give the file unique name?
3-How to save the file into MYSQL database table?
4-How to test the API with postman?
5-How to detect mime type and extension dynamically?
# how to upload image in base64 on server
# Save Base64 Encoded image to file using PHP

Nguồn: https://milchreis.org/

Xem thêm bài viết khác: https://milchreis.org/cong-nghe/

9 COMMENTS

  1. failed to open stream: Permission denied in…on file_put_contents function on server….Though, root user have write and execute permission.

  2. Thank you so much sir…it's working fine for me…I implemented this in my AngularJS+PHP project. Thanks a lot!!!

  3. رائع وياريت يكون في شروحات بالعربي اتوقع هتلاقي نجاح باهر لأن قليل من العرب اللي بيشرح وليهم كود كويس

    اذا انا مش غلطان ولكن من اللكنه دي لكنة مصريه 🙂
    اتمنى لك مزيد من النجاح

  4. This is very much interesting project . Keep up .Is it possible to encode jpeg file to base64 and send it to the server . If possible how can i do it. I tried but not send to the server. Please waiting for your reply. Thanks in advanced

LEAVE A REPLY

Please enter your comment!
Please enter your name here