Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with UTF-8 file/directory names #235

Closed
zaak opened this issue Aug 28, 2014 · 7 comments
Closed

Problem with UTF-8 file/directory names #235

zaak opened this issue Aug 28, 2014 · 7 comments

Comments

@zaak
Copy link

zaak commented Aug 28, 2014

I have following directory structure:

.
└── files
    ├── 繁體中文字
    │   └── test.txt
    └── 繁體中文字.txt

When I call $filesystem->listContents('files') I'm getting following output:

array (size=2)
  0 => 
    array (size=6)
      'dirname' => string 'files' (length=5)
      'basename' => string 'files' (length=5)
      'filename' => string 'files' (length=5)
      'path' => string 'files/繁體中文字' (length=21)
      'type' => string 'dir' (length=3)
      'timestamp' => int 1409223899
  1 => 
    array (size=8)
      'dirname' => string 'files' (length=5)
      'basename' => string '.txt' (length=4)
      'extension' => string 'txt' (length=3)
      'filename' => string '' (length=0)
      'path' => string 'files/繁體中文字.txt' (length=25)
      'type' => string 'file' (length=4)
      'timestamp' => int 1409223047
      'size' => int 0

As you can see filename and basename are invalid. This is caused by lack of multibyte support in pathinfo used in Util::pathinfo(). Expected output is:

array (size=2)
  0 => 
    array (size=7)
      'dirname' => string 'files' (length=5)
      'basename' => string '繁體中文字' (length=15)
      'extension' => string '' (length=0)
      'filename' => string '繁體中文字' (length=15)
      'path' => string 'files/繁體中文字' (length=21)
      'type' => string 'dir' (length=3)
      'timestamp' => int 1409223899
  1 => 
    array (size=8)
      'dirname' => string 'files' (length=5)
      'basename' => string '繁體中文字.txt' (length=19)
      'extension' => string 'txt' (length=3)
      'filename' => string '繁體中文字' (length=15)
      'path' => string 'files/繁體中文字.txt' (length=25)
      'type' => string 'file' (length=4)
      'timestamp' => int 1409223047
      'size' => int 0
@zaak
Copy link
Author

zaak commented Aug 28, 2014

Gah, it was server locale settings messing around. Closing.

@zaak zaak closed this as completed Aug 28, 2014
@zaak
Copy link
Author

zaak commented Aug 28, 2014

Anyone who encountered similar issue - make sure you set locale in your code with setlocale, like:

setlocale(LC_ALL, "en_US.utf8");

@ThaDafinser
Copy link

@zaak did you had this issue under windows or unix?

@zaak
Copy link
Author

zaak commented Nov 25, 2015

@ThaDafinser Linux. On Windows it fails completely if it's about UTF-8 names, but it's PHP itself at fault, not the Flysystem.

@ThaDafinser
Copy link

@zaak thank you.

Just tried on PHP7 and still not solved.

I found this for windows (in case someone comes around here):
https://github.com/kenjiuno/php-wfio

Alternative with com extension:

<?php
$path = '..YOUR_PATH...';

/*
 * COM
 */
$fso = new \COM('Scripting.FileSystemObject', null, CP_UTF8);

$folder = $fso->GetFolder($path);

foreach ($folder->Files as $obj) {
    var_dump($obj->Name);
}

@adrianopedro
Copy link

I also found this problem...
The problem is that at the origin the files are url encoded for safety, but then are not reverted.
In the pathinfo, just treat the filename with urldecode.

public static function pathinfo($path)
    {

       $pathinfo = pathinfo($path) + compact('path');

        //Fix problem with filenames having spacing or special chars 
        //that are url encoded for safety, but then are not reverted.
        $pathinfo['filename'] = urldecode($pathinfo['filename']);

        $pathinfo['dirname'] = array_key_exists('dirname', $pathinfo)
            ? static::normalizeDirname($pathinfo['dirname'])
            : '';

        return $pathinfo;
    }

@ThaDafinser
Copy link

Most or all of the issues here should be resolved with php 7.1
https://github.com/php/php-src/blob/PHP-7.1.0beta2/UPGRADING#L321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants