aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions.php
diff options
context:
space:
mode:
authorpatdenice <patdenice@piwigo.org>2008-11-22 23:34:58 +0000
committerpatdenice <patdenice@piwigo.org>2008-11-22 23:34:58 +0000
commita1e6ae0f159e9cae29683078e358e10d7675badd (patch)
tree53ff5832b9d3d4176f9f748ebc4a24696d3b76dc /admin/include/functions.php
parentb75ddb8e9adaaedc3b451ff1e7a502537e445655 (diff)
merge -c2900 from trunk to branch 2.0.
- Bug fixed: username or password with accented character are now accepted for upgrade. - Simplify query in pwg_session_write function. - Retrieve data with cURL method in fetchRemote function now work with forwarded URL. git-svn-id: http://piwigo.org/svn/branches/2.0@2901 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include/functions.php')
-rw-r--r--admin/include/functions.php23
1 files changed, 13 insertions, 10 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 1c938ca56..a8193d3af 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -1948,6 +1948,10 @@ function cat_admin_access($category_id)
*/
function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
{
+ // After 3 redirections, return false
+ if ($step > 3) return false;
+
+ // Initialize $dest
is_resource($dest) or $dest = '';
// Try curl to read remote file
@@ -1955,16 +1959,20 @@ function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
{
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_URL, $src);
- @curl_setopt($ch, CURLOPT_HEADER, 0);
+ @curl_setopt($ch, CURLOPT_HEADER, 1);
@curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
- is_resource($dest) ?
- @curl_setopt($ch, CURLOPT_FILE, $dest):
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = @curl_exec($ch);
+ $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
@curl_close($ch);
if ($content !== false)
{
- is_resource($dest) or $dest = $content;
+ if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
+ {
+ return fetchRemote($m[1], $dest, $user_agent, $step+1);
+ }
+ $content = substr($content, $header_length);
+ is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
return true;
}
}
@@ -1981,11 +1989,6 @@ function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
}
// Try fsockopen to read remote file
- if ($step > 3)
- {
- return false;
- }
-
$src = parse_url($src);
$host = $src['host'];
$path = isset($src['path']) ? $src['path'] : '/';