Changeset 8079 for trunk/admin/include/functions.php
- Timestamp:
- Dec 11, 2010, 8:50:05 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/functions.php
r8022 r8079 1703 1703 * @return bool 1704 1704 */ 1705 function fetchRemote($src, &$dest, $ user_agent='Piwigo', $step=0)1705 function fetchRemote($src, &$dest, $get_data=array(), $post_data=array(), $user_agent='Piwigo', $step=0) 1706 1706 { 1707 1707 // Try to retrieve data from local file? … … 1719 1719 } 1720 1720 } 1721 1722 // After 3 redirections, return false 1723 if ($step > 3) return false; 1724 1725 // Initialization 1726 $method = empty($post_data) ? 'GET' : 'POST'; 1727 $request = empty($post_data) ? '' : http_build_query($post_data, '', '&'); 1728 $src = add_url_params($src, $get_data, '&'); 1721 1729 1722 1730 // Send anonymous data to piwigo server … … 1738 1746 } 1739 1747 1740 // After 3 redirections, return false1741 if ($step > 3) return false;1742 1743 1748 // Initialize $dest 1744 1749 is_resource($dest) or $dest = ''; … … 1752 1757 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 1753 1758 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 1759 if ($method == 'POST') 1760 { 1761 @curl_setopt($ch, CURLOPT_POST, 1); 1762 @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 1763 } 1754 1764 $content = @curl_exec($ch); 1755 1765 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); … … 1760 1770 if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) 1761 1771 { 1762 return fetchRemote($m[1], $dest, $user_agent, $step+1);1772 return fetchRemote($m[1], $dest, array(), array(), $user_agent, $step+1); 1763 1773 } 1764 1774 $content = substr($content, $header_length); … … 1771 1781 if (ini_get('allow_url_fopen')) 1772 1782 { 1773 $content = @file_get_contents($src); 1783 $opts = array( 1784 'http' => array( 1785 'method' => $method, 1786 'content' => $request, 1787 'user_agent' => $user_agent, 1788 ) 1789 ); 1790 $context = @stream_context_create($opts); 1791 $content = @file_get_contents($src, false, $context); 1774 1792 if ($content !== false) 1775 1793 { … … 1790 1808 } 1791 1809 1792 fwrite($s, 1793 "GET ".$path." HTTP/1.0\r\n" 1794 ."Host: ".$host."\r\n" 1795 ."User-Agent: ".$user_agent."\r\n" 1796 ."Accept: */*\r\n" 1797 ."\r\n" 1798 ); 1810 $http_request = $method." ".$path." HTTP/1.0\r\n"; 1811 $http_request .= "Host: ".$host."\r\n"; 1812 $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n"; 1813 $http_request .= "Content-Length: ".strlen($request)."\r\n"; 1814 $http_request .= "User-Agent: ".$user_agent."\r\n"; 1815 $http_request .= "Accept: */*\r\n"; 1816 $http_request .= "\r\n"; 1817 $http_request .= $request; 1818 1819 fwrite($s, $http_request); 1799 1820 1800 1821 $i = 0; … … 1829 1850 { 1830 1851 fclose($s); 1831 return fetchRemote(trim($m[1]),$dest, $user_agent,$step+1);1852 return fetchRemote(trim($m[1]),$dest,array(),array(),$user_agent,$step+1); 1832 1853 } 1833 1854 $i++;
Note: See TracChangeset
for help on using the changeset viewer.