tripwater
11-03-2006, 10:23 PM
I have a temp folder that clients ftp images into. Now if they upload a file called 'White Lilly.jpg' linux adds a backslash to escape the space in the name. so it becomes 'White\ Lilly.jpg'
The problem I am having is once they upload the file, I read the directory for any files inside and rename them, and move them to another folder.
Like so
$directory = '../tempimages';
$directory_stream = opendir($directory);
while ($entry = readdir($directory_stream))
{
$oldpath = $directory."/".$entry;
$newpath = '../../gallery/'.$imageid.'.jpg';
$cmd = "mv ".$oldpath." ".$newpath;
$ret =0;
exec($cmd, $result, $ret);
}
But the problem is, any file that has a backslash in it will not move. So I echo the $entry var and it does not show the name witha backslash in it but if I go to a shell and look, it does. So the file is not found when calling the 'mv' command because the var $entry is not the same as what is on the server.
So how can I strip the special chars as well as the backslash in the folder before I read it? So that the file name would be WhiteLilly.jpg when I open the dir to read the files. Or is there a better solution?
The filename in the temp dir is not that important in the end result as it is getting renamed to the imageid when I move it to the gallery folder. I just need the $entry var to match what is actually on the server so the mv command will work.
thank you for any help with this
The problem I am having is once they upload the file, I read the directory for any files inside and rename them, and move them to another folder.
Like so
$directory = '../tempimages';
$directory_stream = opendir($directory);
while ($entry = readdir($directory_stream))
{
$oldpath = $directory."/".$entry;
$newpath = '../../gallery/'.$imageid.'.jpg';
$cmd = "mv ".$oldpath." ".$newpath;
$ret =0;
exec($cmd, $result, $ret);
}
But the problem is, any file that has a backslash in it will not move. So I echo the $entry var and it does not show the name witha backslash in it but if I go to a shell and look, it does. So the file is not found when calling the 'mv' command because the var $entry is not the same as what is on the server.
So how can I strip the special chars as well as the backslash in the folder before I read it? So that the file name would be WhiteLilly.jpg when I open the dir to read the files. Or is there a better solution?
The filename in the temp dir is not that important in the end result as it is getting renamed to the imageid when I move it to the gallery folder. I just need the $entry var to match what is actually on the server so the mv command will work.
thank you for any help with this