$permatarfitxes = mysql_query("SELECT valor_variable FROM Preferencies WHERE nom_variable = 'perborrar'");
if ($recordant = mysql_fetch_row($permatarfitxes)){$morituri = $recordant[0]; $lastupdate = $recordant[1];}
$llistamorts = explode(",", $morituri);
/* At this point, $llistamorts is an array containing the names of the files I want to delete */

# Typical FTP connection...
$connftp = ftp_connect("remotehost") or die ("No es pot connectar amb el host: Maggie");
$login = ftp_login ($connftp, "login", "password") or die ("La combinació login/password és incorrecta");
set_time_limit (1200);

# Trying to delete files in $llistamorts
set_time_limit (300);
for ($i=1; $i<=count($llistaids); $i++){
$delete = ftp_delete($connftp, "/petites/$llistamorts[$i].jpg");
}

The problem seems to be that PHP can't delete a missing file. If I try to delete some file that is not on the server, it sends an error and stops execution.

How can avoid that? I've tried using a @ in front of @ftp_delete(), but it stops execution anywat 🙁

    Ummm, I'm not noted for doing things that well, but how about "is_file" in an if?

    # Trying to delete files in $llistamorts
    set_time_limit (300);
    for ($i=1; $i<=count($llistaids); $i++){
       if (is_file("/petites/$llistamorts[$i].jpg")) {
          $delete = ftp_delete($connftp, "/petites/$llistamorts[$i].jpg");
       }

    ?? perhaps works, perhaps too expensive, I don't know....

    HTH, dalecosp

      Write a Reply...