src/Wormhole.php
/**
     * Save a Base64 encoded file to storage.
     *
     * @param  string  $data  Base64 file string
     * @param  string  $directory  The directory in which file should be saved, default is 'files'
     * @param  string  $disk  The disk where the file should upload
     * @return string The file name
     * @throws Exception
     */
Save a Base64 encoded file to storage.
Save a Base64 encoded file to storage .
public function saveBase64File(string $data, string $directory = 'files', string $disk = 'public'): string
    {
        try {
            if (preg_match('/^data:(\w+)\/(\w+);base64,/', $data, $type)) {
                list(, $file64) = explode(',', explode(';', $data)[1]);
                $extension = strtolower($type[2]);
                $filename = Str::random(8).'_'.time().'.'.$extension;
                Storage::disk($disk)->put('/'.$directory.'/'.$filename, base64_decode($file64));
                return $filename;
            } else {
                throw new \Exception('Invalid file data!');
            }
        } catch (Exception $exception) {
            throw $exception;
        }
    }
public function saveBase64File ( string $ data , string $ directory = 'files' , string $ disk = 'public' ) : string { try { if ( preg_match ( '/^data:(\w+)\/(\w+);base64,/' , $ data , $ type ) ) { list ( , $ file64 ) = explode ( ',' , explode ( ';' , $ data ) [ 1 ] ) ; $ extension = strtolower ( $ type [ 2 ] ) ; $ filename = Str :: random ( 8 ) . '_' . time ( ) . '.' . $ extension ; Storage :: disk ( $ disk ) -> put ( '/' . $ directory . '/' . $ filename , base64_decode ( $ file64 ) ) ; return $ filename ; } else { throw new \ Exception ( 'Invalid file data!' ) ; } } catch ( Exception $ exception ) { throw $ exception ; } }
Save a Base64 encoded file to storage.
Save a Base64 encoded file to storage .
// Extract file data from base64 string which will be saved as binary file