PHP script (just the simple solution, add some validation )
//Custom data - Sent Via AJAX post method
$file = $_POST['file']; //This is image sent via AJAX
$fileName = $_POST['fileName'];
$brandingDesc = $_POST['brandingDesc'];
$serverFile = time().$fileName;
$uploads = wp_upload_dir();
$upload_path = $uploads['basedir'];
$serverFileName = $upload_path . "/" . $serverFile;
//Get the base-64 string from data
$filteredData=substr($_POST['file'], strpos($_POST['file'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//Save the image
file_put_contents($serverFileName, $unencodedData);
No comments:
Post a Comment