'What is the most efficient,secure and modern(cross-browser) aproach to compress and upload image(any format) to the server using ajax(jquery) and php?

I am currently compressing the image on client side and sending a base64 string to server using ajax post, on the server I am converting base64 to image file and saving it to servers directory, but I am sure that this is not the best and efficient solution.

So my questions are:

  1. How do I compress an image of any format(to be specific jpg/jpeg/png) on client-side, pass it to php script using post method, securely save(validate the file/base64 post data) the image in the servers directory?

  2. What is the most up to date cross-browser solution for this task?

Maybe you accomplished this task recently and can share your solution(code) or point to multiple different already answered question that have a clear and nice up to date solution to my problem, thank you



Solution 1:[1]

Your program has written the hexadecimal ASCII codes of the string "Hello World!" into a binary file. That's why you are seeing the hexadecimal format in the editor.

For example, 48 for 'H', 65 for 'e', 6C for 'l', etc.

Take a look at the ASCII table.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1