-
-
Save scriptdev/11a0334c635fc889b2ae5c5c81dbfe52 to your computer and use it in GitHub Desktop.
GERAR URL COMPLETA DO ARQUIVO
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 | |
# PEGA A URL PRINCIPAL DO SISTEMA | |
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
$parsed_url = parse_url($url); | |
$base_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path']; | |
$path_parts = pathinfo($base_url); | |
if (isset($path_parts['extension'])) { | |
$base_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . dirname($parsed_url['path']); | |
} | |
# GERA O ARQUIVO PDF NO SERVIDOR | |
$pdf = base64_decode($response->pdf); | |
$file = 'app/output/arquivo_'.uniqid().'.pdf'; | |
file_put_contents($file, $pdf); | |
$url_arquivo = $base_url.$file; | |
# EXEMPLO: https://sistema.com.br/app/output/arquivo_e0910d750195b.pdf | |
# NORMALMENTE É SALVO APENAS A PARTE: app/output/arquivo_e0910d750195b.pdf | |
# COM ESSA SOLUÇÃO É SALVO O CAMINHO COMPLETO DO ARQUIVO (URL + ARQUIVO) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment