PHP | Função SplFileInfo getRealPath()
A função SplFileInfo::getRealPath() é uma função embutida da Biblioteca PHP Padrão (SPL) em PHP que é usada para obter o caminho absoluto do arquivo.
Sintaxe:
int SplFileInfo::getRealPath( void )
Parâmetros: esta função não aceita nenhum parâmetro.
Valores de retorno: esta função retorna o caminho para o arquivo em caso de sucesso.
Os programas abaixo ilustram a função SplFileInfo::getRealPath() em PHP:
Programa 1:
<?php
// PHP Program to illustrate
// Splfileinfo getRealPath function
$file = new SplFileInfo("gfg.txt");
$gfg = $file->getRealPath();
// Print real path if exist
var_dump($gfg . "</br>");
$file = new SplFileInfo(__FILE__);
$gfg = $file->getRealPath();
// Print real path if exist
var_dump($gfg);
?>
Saída:
string(26) "/var/www/html/gfg.txt " string(22) "/var/www/html/cons.php"
Programa 2:
<?php
// PHP program to use array to check multiple files
$GFG = array (
"/home/rajvir/Desktop/GeeksforGeeks/dummy.php",
"/home/rajvir/Desktop/gfg_code.cpp",
"/var/www/html/gfg1.php",
"dummy.php"
);
foreach ($GFG as &$file_name) {
// Create new SplFile Object
$file = new SplFileInfo($file_name);
$gfg = $file->getRealPath();
// Print real path if exist
var_dump($gfg. "</br>");
}
?>
Saída:
string(49) "/home/rajvir/Desktop/GeeksforGeeks/dummy.php " string(38) "/home/rajvir/Desktop/gfg_code.cpp " string(5) " " string(28) "/var/www/html/dummy.php
Referência: http://php.net/manual/en/splfileinfo.getrealpath.php
As postagens do blog Acervo Lima te ajudaram? Nos ajude a manter o blog no ar!
Faça uma doação para manter o blog funcionando.
70% das doações são no valor de R$ 5,00...
Diógenes Lima da Silva