Salve e complimenti per il Forum ... molto utile.
Sto cercando di far funzionare uno script PHP (lato server) ma genera degli errori.
Lo scirpt dovrebbe funzionare tramite la prima parte nell'eseguire un Backup mentre la seconda parte dovrebbe cancellare il file più vecchio presente in una cartella specifica solo se il Backup è andato a buon fine.
Questo è lo script:
<?php
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://www...');
curl_setopt($curl_handle,CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl_handle,CURLOPT_MAXREDIRS, 10000);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
echo "Spiacente ma qualcosa non ha funzionato.";
else
{
DeleteOldestFile();
echo $buffer;
}
function DeleteOldestFile() {
$directory = "/web/..."; // <- inserisci path senza barra finale
$FileExt = ".jpa"; // <- inserisci l'estensione del file o comunque la parte finale da controllare
if (is_dir($directory))
{
if ($directory_handle = opendir($directory))
{
while (($FileName = readdir($directory_handle)) !== false)
{
$FileRef = $directory."/".$FileName;
if ( !is_dir($FileRef) )
{
$FileCtime = filectime($FileRef);
// echo $FileName."<br />".$FileCtime."<br />";
if ( substr($FileName, -strlen($FileExt)) == $FileExt and ( empty($OldestFile) or $FileCtime < $OldestCtime ) )
{
$OldestFile = $FileRef;
$OldestCtime = $FileCtime;
}
}
}
closedir($directory_handle);
if ( empty($OldestFile) ) return;
else
{
echo $OldestFile."<br />";
// unlink($OldestFile);
return;
}
}
}
}
?>
La prima parte dello script non mi funziona ... poi esce scritto il nome corretto almeno 100 volte e poi il seguente errore:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Grazie.
![]()