I made some javascrit code base on image uploader to save an image to the server using php. This is my code :
var reader = new FileReader();
reader.readAsDataURL(files[0]);
reader.onload = function(event) {
var base64 = reader.result;
//console.log(base64);
$.ajax({
url: 'imageapi.php',
method: 'post',
data: {src :base64 },
type:"POST",
contentType:"application/x-www-form-urlencoded",
success: function(response) {
alert('Files uploaded successfully.');
}
});
}
The uploaded file should be : text, png or svg
I want to save the file with proper extension on server. Could anyone help to solve my problem ?
I've tried using this code to get extension but it didn't work
echo $mime_type = finfo_buffer($f, $_POST['src'], FILEINFO_MIME_TYPE);
Please help me, How to save image on server with proper extension
Following code gets filename at first and then extracts it's extension.
$path = $_FILES['src']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);