php import url file to postgresql database

0

I need to import several files to a postgresql database but I could only mount the script to import the files on the local server and now I plan to do it via url. Listing the files via url I can see them in the browser.

The script I mounted for local server (windows) to work:

include ("banco.php");
$path = "C:/arquivos/";
$diretorio = dir($path);
// se quiser listar e abrir o arquivo noutra página
//echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";
while($arquivo = $diretorio -> read()){
echo '<a href="'.$path.$arquivo.'" target="_blank">'.$arquivo.'</a><br />';
$ext = strtolower(strrchr($arquivo, '.'));
pg_query($dbconn, "begin");
$oid = pg_lo_import($dbconn, $path.$arquivo);
$sql = "insert into tabela(nome, arquivo, extensao) 
        select '".substr($arquivo,0,6)."','$oid','$ext'
        where not exists (select * from tabela where nome = '".substr($arquivo,0,6)."')";
$res = pg_query($dbconn,$sql);
pg_query($dbconn, "commit");
}
$diretorio -> close();

What I'm putting together for import via url:

include ("banco.php");

$path = file_get_contents("http://192.168.1.2/arquivos/");

echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";

while($arquivo = $path -> read()){
// se quiser listar e abrir o arquivo noutra página
//echo '<a href="'.$path.$arquivo.'" target="_blank">'.$arquivo.'</a><br />';
$ext = strtolower(strrchr($arquivo, '.'));
pg_query($dbconn, "begin");
$oid = pg_lo_import($dbconn, $path.$arquivo);
$sql = "insert into tabela(nome, arquivo, extensao) 
        select '".substr($arquivo,0,6)."','$oid','$ext'
        where not exists (select * from tabela where nome = '".substr($arquivo,0,6)."')";
$res = pg_query($dbconn,$sql);
pg_query($dbconn, "commit");

}
$diretorio -> close();
    
asked by anonymous 03.10.2018 / 14:33

0 answers