Working with Japanese filenames in PHP 5.3 and Windows Vista?

前端 未结 5 1045
名媛妹妹
名媛妹妹 2020-12-06 09:00

I\'m currently trying to write a simple script that looks in a folder, and returns a list of all the file names in an RSS feed. However I\'ve hit a major wall... Whenever I

5条回答
  •  心在旅途
    2020-12-06 09:20

    Yeah, no, as others stated it, PHP CAN'T do it… Shame on you PHP!

    As others also suggested, one alternative could be to write a proxy in another language that can read those file names:

    Some suggested C, but personally I found Python much more simpler/attractive (here Python3).

    ** BE SURE TO SANITIZE YOUR VARIABLES BEFORE USING THIS **

    $success = (bool)(int)shell_exec('python -c "import os;'.
        'os.chdir(\''.$dir.'\'); '.
        'import urllib.parse; '.
        'file_list = tuple(map(urllib.parse.quote_plus, os.listdir())); '.
        'print(int(\''.urlencode($_GET['src']).'\' in file_list and \''.urlencode($_GET['src'].'.part').'\' not in file_list))"'
    );
    

    Yup, not pretty, but this snippet allowed me to check against file names by urlencode'ing them.

    (Ndla: That particular snippet was used to find out when a file was done downloading with Firefox without having to mess with the API. Not the best but WORKING and fast to setup)

提交回复
热议问题