My question is: how can/should I create a directory, test if exists and get it's contents using special characters in the name?
My scenario: I need to create a directory, put some images there, and then get that directory contents. That directory may contain a special characters. For example galería
When creating the directory with mkdir()
, the name changed to galerÃa
. So the solution that worked for me was to utf8_decode()
the string.
So far so good...
I upload images to that directory...
Then I attempted to scan the directory doing:
$gallery = [];
if(is_dir($path)) //$path contains a valid path including my recently created directory
{
$gallery = glob("$path*{.jpg,.gif,.png}", GLOB_BRACE);
}
echo "<pre>";
print_r($gallery);
echo "</pre>";
But is_dir()
returned false. So I had to do this to get inside the if statement:
$path = mb_convert_encoding($path, "ISO-8859-1", "UTF-8");
Now is_dir()
works, but glob()
doesn't. At this point I should mention that after mb_convert_encoding()
, the name I'm getting is galer�a
Any help?
EDIT: If I use pictures
for directory name, I don't need to use utf8_decode()
neither mb_convert_encoding()
. mk_dir()
, is_dir()
and glob()
work flawlessly