Last active
October 22, 2024 12:33
-
-
Save rogeriotaques/03578d066dbe302b74f2915fbaaaa9dd to your computer and use it in GitHub Desktop.
Converts base64 string back to a pdf file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function uploadFileFromBlobString($base64string = '', $file_name = '', $folder = '') | |
{ | |
$file_path = ""; | |
$result = 0; | |
// Convert blob (base64 string) back to PDF | |
if (!empty($base64string)) { | |
// Detects if there is base64 encoding header in the string. | |
// If so, it needs to be removed prior to saving the content to a phisical file. | |
if (strpos($base64string, ',') !== false) { | |
@list($encode, $base64string) = explode(',', $base64string); | |
} | |
$base64data = base64_decode($base64string, true); | |
$file_path = "{$folder}/{$file_name}"; | |
// Return the number of bytes saved, or false on failure | |
$result = file_put_contents("{$this->_assets_path}/{$file_path}", $base64data); | |
} | |
return $result; | |
} // uploadFileFromBlobString |
I'm glad it has helped you! 🤗
Thank you for helping me =))
I appreciate.
My pleasure, @minhnq49!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, sir you save my time. I am exploring solutions from almost 2 hours.