Hi all,
I'am newbie with php, and i'am actually working to get a script to work as a cron job on DA, but a need help!
Actually it is impossible for me to know if this script work or if not working, (there is no log or something else in the script to see that)
Here what i put i the crontab:
*/5 * * * * /home/user/delfiles.php
Script is set with permissions 777
Script is actually at the root emplacement.(when i connect with ftp with this user i see the script at the root)
This script is used to delete automatically all the .jpg in the folder "Test1" when this files are aged more than 3600s (1hour)
Here the script used (php):
<?php
//notre fonction paramétrée
suppression( "Test1" , "jpg" , "3600" );
//la fonction en question
function suppression($dossier_traite , $extension_choisie, $age_requis)
{
//on ouvre le dossier
$repertoire = opendir($dossier_traite);
//on lance notre boucle qui lira les fichiers un par un
while(false !== ($fichier = readdir($repertoire)))
{
//on met le chemin du fichier dans une variable simple
$chemin = $dossier_traite."/".$fichier;
//les variables qui contiennent toutes les infos nécessaires
$infos = pathinfo($chemin);
$extension = $infos['extension'];
$age_fichier = time() - filemtime($chemin);
//on n'oublit pas LA condition sous peine d'avoir quelques surprises
if($fichier!="." AND $fichier!=".." AND !is_dir($fichier)
$extension == $extension_choisie AND $age_fichier > $age_requis)
{
unlink($chemin);
}
}
closedir($repertoire); //on ferme !
}
?>
The problem is these images *.jpg under the folder "Test1" are never deleted (aged more than 3600s) so i think the crontab configuration
in DA i set is not good, or this script not working at all !
- What do you mean? ,
- did i set correctly crontab?,
- and do you think my script php is correct?
Thanks for the all help you can give !!! (and sorry for my bad english here)
Vincent
I'am newbie with php, and i'am actually working to get a script to work as a cron job on DA, but a need help!
Actually it is impossible for me to know if this script work or if not working, (there is no log or something else in the script to see that)
Here what i put i the crontab:
*/5 * * * * /home/user/delfiles.php
Script is set with permissions 777
Script is actually at the root emplacement.(when i connect with ftp with this user i see the script at the root)
This script is used to delete automatically all the .jpg in the folder "Test1" when this files are aged more than 3600s (1hour)
Here the script used (php):
<?php
//notre fonction paramétrée
suppression( "Test1" , "jpg" , "3600" );
//la fonction en question
function suppression($dossier_traite , $extension_choisie, $age_requis)
{
//on ouvre le dossier
$repertoire = opendir($dossier_traite);
//on lance notre boucle qui lira les fichiers un par un
while(false !== ($fichier = readdir($repertoire)))
{
//on met le chemin du fichier dans une variable simple
$chemin = $dossier_traite."/".$fichier;
//les variables qui contiennent toutes les infos nécessaires
$infos = pathinfo($chemin);
$extension = $infos['extension'];
$age_fichier = time() - filemtime($chemin);
//on n'oublit pas LA condition sous peine d'avoir quelques surprises

if($fichier!="." AND $fichier!=".." AND !is_dir($fichier)
$extension == $extension_choisie AND $age_fichier > $age_requis)
{
unlink($chemin);
}
}
closedir($repertoire); //on ferme !
}
?>
The problem is these images *.jpg under the folder "Test1" are never deleted (aged more than 3600s) so i think the crontab configuration
in DA i set is not good, or this script not working at all !
- What do you mean? ,
- did i set correctly crontab?,
- and do you think my script php is correct?
Thanks for the all help you can give !!! (and sorry for my bad english here)
Vincent