Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
* Added $options param to G\fetch_url (custom curl headers).
Browse files Browse the repository at this point in the history
* Added clearstatcache to G\get_image_fileinfo (fixes cache issues in some servers)
* Fixed bug in G\get_image_fileinfo function
  • Loading branch information
rodber committed Jun 4, 2017
1 parent 0e95cc6 commit da673a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/G/G.php
Expand Up @@ -18,7 +18,7 @@

if(!defined('access') or !access) die("This file cannot be directly accessed.");

define('G_VERSION', '1.0.37');
define('G_VERSION', '1.0.38');

// Error reporting setup
@ini_set('log_errors', TRUE);
Expand Down
15 changes: 12 additions & 3 deletions lib/G/functions.php
Expand Up @@ -1433,10 +1433,10 @@ function get_regex_match($regex, $delimiter='/', $subject, $key=NULL) {
* Fetch the contents from an URL
* if $file is set the downloaed file will be saved there
*/
function fetch_url($url, $file=NULL) {
function fetch_url($url, $file=NULL, $options=[]) {
if(!$url) {
throw new Exception('missing $url in ' . __FUNCTION__);
return false;
return FALSE;
}

if(ini_get('allow_url_fopen') !== 1 && !function_exists('curl_init')) {
Expand All @@ -1460,6 +1460,12 @@ function fetch_url($url, $file=NULL) {
curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); // this needs zlib output compression enabled (php)
curl_setopt($ch, CURLOPT_VERBOSE, 0);

if(is_array($options) && count($options) > 0) {
foreach($options as $k => $v) {
curl_setopt($ch, $k, $v);
}
}

if($file) {
// Save the file to $file destination
$out = @fopen($file, 'wb');
Expand Down Expand Up @@ -1711,10 +1717,13 @@ function extension_to_mime($ext) {

// Retrieves info about the current image file
function get_image_fileinfo($file) {

clearstatcache($file); // http://php.net/manual/es/function.clearstatcache.php (add G\ magic for those)

$info = getimagesize($file);
$filesize = @filesize($file);

if(!$info || !$filesize) return false;
if(!$info || $filesize === FALSE) return FALSE;

$mime = strtolower($info['mime']);

Expand Down

0 comments on commit da673a3

Please sign in to comment.