Skip to content

Instantly share code, notes, and snippets.

@RoesWibowo
Created July 12, 2015 09:51
Show Gist options
  • Save RoesWibowo/94b2d1cf941b06c101ef to your computer and use it in GitHub Desktop.
Save RoesWibowo/94b2d1cf941b06c101ef to your computer and use it in GitHub Desktop.
Save base64 encoded files
/**
* @param $fileString
* @param $location
* @param $filename
* @return array
*/
function saveFile($fileString, $location, $filename) {
$result = [];
$split = explode(';', $fileString);
if (count($split)) {
$hash = explode(',', $split[1]);
if(count($hash)) {
$filename2 = date('YmdHis').'_'.$filename;
file_put_contents($location.'/'.$filename2, base64_decode($hash[1]));
$result = [
'filename' => $filename,
'uploaded' => $filename2
];
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment