Other LỖI addon [bd] Image

Discussion in 'Template Modifications' started by MacKen, Oct 10, 2016.

  1. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
    Như tiêu đề có nhiều người lỗi thumbnail ảnh đại diện như không get được ảnh hay get được ảnh rồi lại lỗi gọi hàm function.

    Nên mình lập ra topic này để đặt câu hỏi để được trả lời tại đây nhé
     
  2. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
    Qua tìm hiểu mình thấy có người lỗi không get được ảnh do lỗi hàm file_get_contents

    Để khắc phục lỗi file_get_contents thì ta mở file root/bdImage/thumbnail.php làm thế này:

    Tìm hàm :

    PHP:
    if (Zend_Uri::check($uri))
        {
            
    // this is a remote uri, try to cache it first
            
    if (!bdImage_Helper_File::existsAndNotEmpty($originalCachePath))
            {
                
    XenForo_Helper_File::createDirectory(dirname($originalCachePath), true);
                
    file_put_contents($originalCachePathfile_get_contents($uri));
            }

            
    // switch to use the cached original file
            // doing this will reduce server load when a new image is uploaded and started to
            // appear in different places with different sizes/modes
            
    $uri $originalCachePath;
        }
    Ta thay dòng:
    Code:
    file_put_contents($originalCachePath, file_get_contents($uri));
    Thành:

    Code:
    file_put_contents($originalCachePath, file_get_contents_null($uri));
    Sau đó ta thêm functionfile_get_contents_null sau dòng:

    Code:
    $originalCachePath = bdImage_Integration::getOriginalCachePath($uri);
    
    Code sau:

    PHP:
    function file_get_contents_null($image_url) {
      if (
    function_exists('curl_init')) {
        
    $opts                                   = array();
        
    $http_headers                           = array();
        
    $http_headers[]                         = 'Expect:';
        
    $opts[CURLOPT_USERAGENT]= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1';

        
    $opts[CURLOPT_URL]                      = $image_url;
        
    $opts[CURLOPT_HTTPHEADER]               = $http_headers;
        
    $opts[CURLOPT_CONNECTTIMEOUT]           = 10;
        
    $opts[CURLOPT_TIMEOUT]                  = 60;
        
    $opts[CURLOPT_HEADER]                   = FALSE;
        
    $opts[CURLOPT_BINARYTRANSFER]           = TRUE;
        
    $opts[CURLOPT_VERBOSE]                  = FALSE;
        
    $opts[CURLOPT_SSL_VERIFYPEER]           = FALSE;
        
    $opts[CURLOPT_SSL_VERIFYHOST]           = 2;
        
    $opts[CURLOPT_RETURNTRANSFER]           = TRUE;
        
    $opts[CURLOPT_FOLLOWLOCATION]           = TRUE;
        
    $opts[CURLOPT_MAXREDIRS]                = 2;
        
    $opts[CURLOPT_IPRESOLVE]                = CURL_IPRESOLVE_V4;

        
    # Initialize PHP/CURL handle
        
    $ch curl_init();
        
    curl_setopt_array($ch$opts);
        
    $content curl_exec($ch);
        
        
    # Close PHP/CURL handle
        
    curl_close($ch);
      }
    // use file_get_contents
      
    elseif (ini_get('allow_url_fopen')) {
        
    $content file_get_contents($image_url);
      }

      
    # Return results
      
    return $content;
    }
    ĐẾN ĐÂY TA ĐÃ HOÀN THÀNH
     
    Last edited: Oct 10, 2016
  3. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
    Qua tìm hiểu thêm mình lại phát hiện thấy nhiều người lỗi không thể convert ảnh được file có đuôi png ta bắt gặp được lỗi :


    Ex:
    PHP:
    https://khatvongsong.vn/bdImage/thumbnail.php?url=http%3A%2F%2Fimg.f41.suckhoe.vnecdn.net%2F2016%2F10%2F08%2Fnhung-cach-tang-chi-so-IQ-1564-3923-1907-1475897667.png&size=218&mode=150&hash=11cd955dfec6af82117a5924d690c85a

    Link ảnhhttp://img.f41.suckhoe.vnecdn.net/2016/10/08/nhung-cach-tang-chi-so-IQ-1564-3923-1907-1475897667.png


    PHP:
    Fatal errorCall to a member function getWidth() on a non-object in E:\www\domain\bdImage\thumbnail.php on line ......
    ta tìm dòng lỗi thì thì ta mở file root/bdImage/thumbnail.php

    bắt gặp lỗi dòng này:

    PHP:
    // exact crop
                    
    $origRatio $image->getWidth() / $image->getHeight();
    Thế ta đã hiểu sao lỗi thế là do không thể gọi hàm function getWidth()

    Mình tìm đường dẫn file thumbnail E:\www\domain\internal_data\bdImage\cache\ thì thấy file ảnh tồn tại . (file có đuôi là ....orig)

    Kiểm tra Properties thì file ....orig không thấy kích thước width hoặc height

    Những file convert được thì lại biết được thumbnail file .orig có kích thước width và height



    Để khắc phục lỗi này thì mình chưa tìm ra HIHIHIHIHIHII
     
    Last edited: Oct 10, 2016
  4. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
  5. Jindo_Katori

    Jindo_Katori Thượng Đế

    Joined:
    Mar 1, 2015
    Messages:
    1,463
    Likes Received:
    1,114
    Trophy Points:
    113
    Gender:
    Male
    Occupation:
    http://tuyhoaplus.com
    Location:
    http://tuyhoaplus.com
    Home Page:
    Cảm ơn bác đã chia sẽ nhé
    Site mình hình như cũng bị nhưng mà lười sửa quá thành ra để vậy luôn
     
  6. PVS

    PVS Cộng Sự Đặc Biệt Staff Member

    Joined:
    Feb 28, 2015
    Messages:
    11,755
    Likes Received:
    7,002
    Trophy Points:
    113
    Gender:
    Male
    Location:
    Huế
    Home Page:
    Đây là các lỗi thường gặp và cách khắc phục luôn hả :)
     
  7. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
    Hôm nay tranh thủ thời gian rảnh từ bệnh viện đa khoa quảng ngãi thăm người thân về chợt nhớ ra lỗi này chưa khắc phục được ... rồi bắt tay vào làm.

    Cuối cùng đã thành công.

    Ex:
    https://khatvongsong.vn/bdImage/thumbnail.php?url=http://img.f41.suckhoe.vnecdn.net/2016/10/08/nhung-cach-tang-chi-so-IQ-1564-3923-1907-1475897667.png&size=218&mode=150&hash=11cd955dfec6af82117a5924d690c85a

    Link ảnh: http://img.f41.suckhoe.vnecdn.net/2016/10/08/nhung-cach-tang-chi-so-IQ-1564-3923-1907-1475897667.png

    Link trên trước đây ko get được 1 số file png ... do ko gọi được hàm getWidth()

    Và cho đến lúc này đã làm thành công:

    mình sẽ làm bản update
    [bd] Image 1.0.3
     
    Last edited: Oct 25, 2016
  8. Jindo_Katori

    Jindo_Katori Thượng Đế

    Joined:
    Mar 1, 2015
    Messages:
    1,463
    Likes Received:
    1,114
    Trophy Points:
    113
    Gender:
    Male
    Occupation:
    http://tuyhoaplus.com
    Location:
    http://tuyhoaplus.com
    Home Page:

    Ngồi hóng cái này của bác @MacKen
     
  9. bannvph00701

    bannvph00701 Thượng Đế

    Joined:
    Nov 14, 2015
    Messages:
    44
    Likes Received:
    12
    Trophy Points:
    8
    Gender:
    Male
    Occupation:
    Seoer
    Location:
    Mỹ Đình
    Home Page:
    Cảm ơn mọi người đã chia sẻ ạ. Em bị lỗi tương tự và đã làm được rồi ạ hihi. cảm ơn mọi ng
     
  10. MacKen

    MacKen Thượng Đế

    Joined:
    Nov 30, 2015
    Messages:
    623
    Likes Received:
    526
    Trophy Points:
    93
    Location:
    VN
    HÔm nay mình ngồi làm lại thì fix được số lỗi như đã nói trên và không làm những bước trên chỉ cần thêm 1 dòng ok

    Cụ thể các bạn download file đính kèm rồi unzip up đè lên file thumbnail.php theo đường dẫn sau:

    root/bdImage/thumbnail.php
     

    Attached Files:

    KHUCTHUYDU likes this.
  11. onlyonelove

    onlyonelove Thượng Đế

    Joined:
    Nov 3, 2015
    Messages:
    370
    Likes Received:
    200
    Trophy Points:
    43
    Gender:
    Male
    Occupation:
    Code tập sự
    Location:
    Đồng Nai
    Home Page:

Share This Page