how can i save image server side i have this code but for some reason the image that i upload to the server is saved as text/x-generic. what can i do to fix this?
<?php
function base64_to_image($base64_string) {
$data = explode(',', $base64_string);
$ext = "";
switch ($data[0]) {
case "data:image/png;base64";
$ext = "png";
break;
case "data:image/jpg;base64";
$ext = "jpg";
break;
case "data:image/jpeg;base64";
$ext = "jpg";
break;
case "data:image/gif;base64";
$ext = "gif";
break;
}
$milli = round(microtime(true) * 1000);
$output_file = "img/" . date('Y-m-d_H:i:s') . "." . $milli . "." . $ext;
$ifp = fopen($output_file, "wb");
fwrite($ifp, base64_decode($data[1]));
fclose($ifp);
return $ifp;
}
$file = base64_to_image($_POST['file']);
var_dump($file);
?>