I would like to empty a folder (with chmod 777) before uploading a file :
$files = glob($targetdir); // get all file names
foreach($files as $file)
{ // iterate files
if(is_file($file))
unlink($file); // delete file
}
My folder has a right path builded with this code :
$targetdir = 'cartes_identites/'.$mds['nom'].' '.$mds['prenom'].'_verso';
My folder still full of files, I have to keep only one, uploaded with this code :
if (move_uploaded_file($_FILES['id_card_recto']['tmp_name'], $targetfile))
{
echo "file uploaded succeeded";
}