Created
January 13, 2020 15:46
-
-
Save paulodutra/75aa9a78037c36531d3132d19998606c to your computer and use it in GitHub Desktop.
Obtendo a extensão do arquivo base64 utilizando a função explode do PHP
This file contains hidden or 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 | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Storage; | |
class UploadController extends Controller | |
{ | |
/** | |
* sendFile: Método responsável por enviar o arquivo no formato base64 | |
*/ | |
public function sendFile(Request $request) | |
{ | |
if($request->has('file') && strpos($request->file, ';base64')){ | |
$base64 = $request->file; | |
//obtem a extensão | |
$extension = explode('/', $base64); | |
$extension = explode(';', $extension[1]); | |
$extension = '.'.$extension[0]; | |
}else{ | |
return response() | |
->json(['message' => 'Envie o atributo file no formato base64'], 422); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment