Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: mkdir urlencode

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default mkdir urlencode

    i am trying to apply foreign language to my make directory function
    when i
    Code:
    $nTitle = urlencode($_POST['entryItm']);
    $newDir = mkdir("./CONTENT/" . $nTitle , 01777, true);
    it creates a folder "%E5%B8%BD%E5%AD%90"

    but when i try to access the folder through header like
    mydomain.com/CONTENT/%E5%B8%BD%E5%AD%90/SAM_0070.JPG

    i get
    mydomain.com/CONTENT/帽子/SAM_0070.JPG

    + error 404.
    how can i reference this folder?
    Last edited by ggalan; 10-23-2011 at 08:57 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    why are you url-encoding the directory name?

    try
    Code:
    mydomain.com/CONTENT/%25E5%25B8%25BD%25E5%25AD%2590/SAM_0070.JPG

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    thanks but how would i get it from my encoding to yours? meaning what can i do to get it from
    %E5%B8%BD%E5%AD%90
    to
    %25E5%25B8%25BD%25E5%25AD%2590

    im encoding so i can reference the directory created using foreign characters, otherwise i get something like this

    手袋

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by ggalan View Post
    thanks but how would i get it from my encoding to yours? meaning what can i do to get it from
    %E5%B8%BD%E5%AD%90
    to
    %25E5%25B8%25BD%25E5%25AD%2590
    PHP Code:
    print urlencode("%E5%B8%BD%E5%AD%90");
    // prints %25E5%25B8%25BD%25E5%25AD%2590 
    Quote Originally Posted by ggalan View Post
    im encoding so i can reference the directory created using foreign characters, otherwise i get something like this
    手袋
    well, I think you've got a problem there.

    you're actually naming the directory with the character references, not the characters they refer to (which is why you have to double-url-encode things to get the directory).

    depending on your machine/system, you could name directories using the actual characters. PHP won't mind. The bigger problem (unless the intended audience is language-specific) is having users that can type those characters into the address bar - though it would be easier than using character references.

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    hmmm, i guess i need something like this but this doesnt work

    Code:
    <img src = './../CONTENT/' . print urlencode("%E5%B8%BD%E5%AD%90")  . '/title.jpg' />

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I agree with traq. This doesn't make sense: you want to use the characters, but you're not using them. I understand the desire to use the characters, but it doesn't help if you don't actually use them-- you would be better just using random names.
    Also, you probably can use the characters directly, even using urlencode(), but the way you're doing it, you're using that twice and it's making more characters that can't be encoded properly (like the %). There are reasons to avoid using characters like that in a URL (although I don't believe there are any true technical limitations, not to say it will always work), but double urlencoding them isn't helping anything.

    One option would be to write the characters out in their Latin-alphabet forms. This could be very difficult if you don't have an easy way to automatically convert them, but maybe you could find some software to do that. I'm not sure if that's Japanese or Chinese you're using, but either way there are generally recognizable transcription formats into the Latin-alphabet (a-z) so you could use that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i think my question has gotten abstracted
    im simply trying to use special characters to make a directory.
    if i dont encode then i get something like this

    手袋

    is that ok to work with?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not sure I understand. Why are you using urlencode() then?

    urlencode() is specifically (and only) to be used when you are creating a link for a browser. So, for example "test directory" would be "test%20directory"-- you would still name the directory "test directory" but use the format "test%20directory" when you generate a link to it. If you do this while creating the directory, then it will mean you need to use it twice and it will never look like the right URL. Also, sometimes you don't need to use urlencode() if you can use the characters directly, but I think this varies by browser. Regardless, if you do use urlencode() you won't see the characters, so I don't understand the advantage.


    Now, if you do want to create a directory named that, you should be able to do it without any trouble. If it is naming it with an unexpected format, then there is a character encoding conversion problem. You need to determine what the settings are for PHP, for your server, and for your webpages, and convert between them. It might just be easier to use trial and error in PHP to find the right combination for conversion.

    No, you can't use what you get now or it will always be in a different encoding and you can't refer to with the original characters except through the same exact situation (so you probably won't be able to access it when you need to).

    This is a system configuration issue, in PHP and/or your server's operating system. In some systems it might not be possible to use characters like that, but in most systems I've used it is possible, but it depends on your system, I guess.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    how about this, i enter some foreign characters like
    Code:
    $nTitle = htmlspecialchars($_POST['entryItm']);
    $newDir = mkdir("./CONTENT/" . $nTitle , 01777, true);
    which gives me a directory called

    手袋

    then since i didnt encode anything my output gets
    Code:
    mydomain.com/CONTENT/帽子/SAM_0070.JPG
    how can i go from that to this?
    Code:
    mydomain.com/CONTENT/手袋/SAM_0070.JPG

  10. #10
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i think i posted this last question before i realized there was a reply.

    how would you handle something like this using foreign characters?
    i cant do this
    One option would be to write the characters out in their Latin-alphabet forms.
    btw, i got the encode idea from here
    http://stackoverflow.com/questions/1...-utf-8-strings
    Last edited by ggalan; 10-23-2011 at 08:19 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •