SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Australia
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UTF-8 encoded PHP files...

    I have written code and save them into PHP file as UTF-8 encoding using UltraEdit.

    But it happens that image loading doesn't work. I wonder what can be done to get around this problem... the code looks like this...

    <?php
    header("Content-type: image/jpeg");
    readfile("image.jpg");
    ?>

    It works if I encoded my PHP file to ASCII DOS/UNIX format... but not U8-DOS (UTF-8).

    I'm sure there's a workaround to this image problem. I need help from people who use UltraEdit or encode pages in UTF-8.

    I have worked on other PHP pages that are encoded in UTF-8 format and there's not reason why it shouldn't work like the rest. I'm just probably unsure about how to do it. I'm not a real geek in UTF-8.

    There are a couple of functions in the mbstring extension. Probably someone can tell me how to use them... ^^

    Thanks in advance.

  2. #2
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just try:
    PHP Code:
    header("content-type: text/html; charset=UTF-8");
    header("Content-type: image/jpeg");
    //.... 

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Australia
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No it does not work....

    No it doesn't work...

    Like I said the problem comes from the encoding of the PHP file and not the HTTP output...
    When file is encoding in ASCII format, the code works...
    When file is encoded in UTF-8 format, the code doesn't work at all...
    No image is displayed... all I see is a placeholder with nothing...

    Using PHP v4.3.9 and Apache v2.0.50

    Please test and review...

  4. #4
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $filename "image.jpg";
    if (
    $fp = @ fopen($filename'r')) 

        
    header("Content-type: image/jpeg");
        if (
    strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) 
        { 
            
    header("Content-Disposition: filename=" $filename); // For IE 
        

        else 
        { 
            
    header("Content-Disposition: attachment; filename=" $filename); // For Other browsers 
        

         
        while (@ !
    feof($fp)) 
        { 
            echo 
    fread($fp1024); 
        } 


  5. #5
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it done well , Apache 2.0.50 / PHP 5.0.2 / Windows Server 2003


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
  •