mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-07 18:18:18 +01:00
Fix: Delete file functionw works with filename with special chars
This commit is contained in:
@@ -2248,10 +2248,10 @@ function dol_delete_file($file,$disableglob=0)
|
|||||||
{
|
{
|
||||||
//print "x".$file." ".$disableglob;
|
//print "x".$file." ".$disableglob;
|
||||||
$ok=true;
|
$ok=true;
|
||||||
$newfile=utf8_check($file)?utf8_decode($file):$file; // glob function accepts only ISO string
|
$file_osencoded=dol_osencode($file); // New filename encoded in OS filesystem encoding charset
|
||||||
if (empty($disableglob))
|
if (empty($disableglob))
|
||||||
{
|
{
|
||||||
foreach (glob($newfile) as $filename)
|
foreach (glob($file_osencoded) as $filename)
|
||||||
{
|
{
|
||||||
$ok=unlink($filename); // The unlink encapsulated by dolibarr
|
$ok=unlink($filename); // The unlink encapsulated by dolibarr
|
||||||
if ($ok) dol_syslog("Removed file ".$filename,LOG_DEBUG);
|
if ($ok) dol_syslog("Removed file ".$filename,LOG_DEBUG);
|
||||||
@@ -2260,9 +2260,9 @@ function dol_delete_file($file,$disableglob=0)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$ok=unlink($newfile); // The unlink encapsulated by dolibarr
|
$ok=unlink($file_osencoded); // The unlink encapsulated by dolibarr
|
||||||
if ($ok) dol_syslog("Removed file ".$newfile,LOG_DEBUG);
|
if ($ok) dol_syslog("Removed file ".$file_osencoded,LOG_DEBUG);
|
||||||
else dol_syslog("Failed to remove file ".$newfile,LOG_ERR);
|
else dol_syslog("Failed to remove file ".$file_osencoded,LOG_ERR);
|
||||||
}
|
}
|
||||||
return $ok;
|
return $ok;
|
||||||
}
|
}
|
||||||
@@ -2275,8 +2275,8 @@ function dol_delete_file($file,$disableglob=0)
|
|||||||
*/
|
*/
|
||||||
function dol_delete_dir($dir)
|
function dol_delete_dir($dir)
|
||||||
{
|
{
|
||||||
$newdir=utf8_check($dir)?utf8_decode($dir):$dir;
|
$dir_osencoded=dol_osencode($dir);
|
||||||
return rmdir($newdir);
|
return rmdir($dir_osencoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2287,32 +2287,30 @@ function dol_delete_dir($dir)
|
|||||||
*/
|
*/
|
||||||
function dol_delete_dir_recursive($dir,$count=0)
|
function dol_delete_dir_recursive($dir,$count=0)
|
||||||
{
|
{
|
||||||
//dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
|
dol_syslog("functions.lib:dol_delete_dir_recursive ".$dir,LOG_DEBUG);
|
||||||
$newdir=utf8_check($dir)?utf8_decode($dir):$dir;
|
$dir_osencoded=dol_osencode($dir);
|
||||||
if ($handle = opendir("$newdir"))
|
if ($handle = opendir("$dir_osencoded"))
|
||||||
{
|
{
|
||||||
while (false !== ($item = readdir($handle)))
|
while (false !== ($item = readdir($handle)))
|
||||||
{
|
{
|
||||||
// readdir return value in ISO and we want UTF8 in memory
|
if (! utf8_check($item)) $item=utf8_encode($item); // should be useless
|
||||||
$newitem=$item;
|
|
||||||
if (! utf8_check($item)) $item=utf8_encode($item);
|
|
||||||
|
|
||||||
if ($item != "." && $item != "..")
|
if ($item != "." && $item != "..")
|
||||||
{
|
{
|
||||||
if (is_dir("$newdir/$newitem"))
|
if (is_dir(dol_osencode("$dir/$item")))
|
||||||
{
|
{
|
||||||
$count=dol_delete_dir_recursive("$dir/$item",$count);
|
$count=dol_delete_dir_recursive("$dir/$item",$count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unlink("$newdir/$newitem");
|
dol_delete_file("$dir/$item",1);
|
||||||
$count++;
|
$count++;
|
||||||
//echo " removing $dir/$item<br>\n";
|
//echo " removing $dir/$item<br>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
rmdir($newdir);
|
dol_delete_dir($dir);
|
||||||
$count++;
|
$count++;
|
||||||
//echo "removing $dir<br>\n";
|
//echo "removing $dir<br>\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user