Ignore:
Timestamp:
Nov 5, 2009, 11:15:41 PM (14 years ago)
Author:
vdigital
Message:

[PiwigoPress]

  • Alternate pwg_get_contents (cURL)
  • Generated \r\n in code
  • Readme FAQ
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/piwigopress/PiwigoPress_get.php

    r4125 r4216  
    1919        $pwg_prev_host = $host;
    2020        $mode = $pwg_mode;
    21         //$mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL
     21        // $mode = 'ch'; // Forcing a test '' all, 'fs' fsockopen, 'ch' cURL
    2222
    2323// 1 - The simplest solution: file_get_contents
     
    3434        }
    3535        if ( $mode == '' ) $mode = 'fs';
    36         if ( $pwg_mode == '' ) $pwg_mode = 'fs';
     36        if ( $pwg_mode == '' ) $pwg_mode = 'fs'; // Remind it
    3737// 2 - Often accepted access: fsockopen
    3838        if ($mode == 'fs') {
     
    5656                }
    5757        }
    58         $return["stat"] = 'failed';
    59         $pwg_mode = 'failed';
    60         return serialize($return);
    6158
    62 // Not active cURL right now
    63         if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch';
     59        if ( $pwg_mode == 'fs' ) $pwg_mode = 'ch'; // Remind it
    6460// 3 - Sometime another solution: curl_exec
    6561// See http://fr2.php.net/manual/en/curl.installation.php
    6662  if (function_exists('curl_init') and $pwg_mode == 'ch') {
    6763                $ch = @curl_init();
     64                @curl_setopt($ch, CURLOPT_URL, $url);
     65                @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    6866                @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    69                 @curl_setopt($ch, CURLOPT_URL, $url);
    7067                @curl_setopt($ch, CURLOPT_HEADER, 1);
    7168                @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
     
    7673                $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    7774                @curl_close($value);
    78                 if ($value !== false and $status >= 200 and $status < 400)
    79                                 $value = substr($value, $header_length);
     75                if ($value !== false and $status >= 200 and $status < 400) {
     76                        $value = substr($value, $header_length);
     77                        // echo '<br/>-ch- ('. $value . ') <br/>';
     78                        return $value;
     79                }
     80                else $pwg_mode = 'failed'; // Sorry but remind it as well
    8081        }
    8182
    8283        // No other solutions
    8384        $return["stat"] = 'failed';
    84         echo '<br/>- pwg_get_contents: failed on file_get, fsockopen and cURL processes<br/>';
    85         $pwg_mode = 'failed';
     85        // echo '<br/>- pwg_get_contents: failed on file_get, fsockopen and cURL processes<br/>';
    8686        return serialize($return);
    8787}
Note: See TracChangeset for help on using the changeset viewer.