--- upload.txt	Sun Aug 13 22:20:31 2006
+++ upload.php	Mon Aug 14 23:19:15 2006
@@ -1392,9 +1392,15 @@
 
                 }
 
-                // Open a stream to the resource.
-                $fp = fopen($_POST['URI_array'][$counter],"rb");
-
+                if( ini_get('allow_url_fopen') == 1)
+                {
+                  // Open a stream to the resource.
+                  $fp = fopen($_POST['URI_array'][$counter],"rb");
+                }
+                else
+                { 
+                  $fp = curl_init($_POST['URI_array'][$counter]);
+                }
                 // Check to see if the resource was opened.
                 if (!$fp) {
 
@@ -1456,8 +1462,23 @@
                     }
 
                 } else {
-
-                    $header = stream_get_meta_data($fp);
+                    if(  ini_get('allow_url_fopen') == 1)
+                    {
+                      $header = stream_get_meta_data($fp);
+                    }
+                    else
+                    {
+                      curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
+                      $content = curl_exec($fp);
+
+                      // 模擬 stream_get_meta_data
+                      $data = curl_getinfo($fp);
+                      
+                      $header['wapper_data'][] = $data['http_code'];
+                      $header['wapper_data'][] = 'content-type: '.$data['content_type'];
+                      $header['wapper_data'][] = 'content-length: '.$data['download_content_length'];
+                      
+                    }
 
                     if($header === 'FALSE') {
 
@@ -1577,7 +1598,14 @@
                     }
 
                     // Close the file pointer if we were able to open it.
-                    fclose($fp);
+                    if( ini_get('allow_url_fopen') == 1)
+                    {
+                      fclose($fp);
+                    }
+                    else
+                    {
+                      curl_close($ch); 
+                    }
 
                 }
 
@@ -1660,10 +1688,15 @@
             $tempname = $prefix . $seed . '.' . $suffix;
 
             // The file name $path_to_image has been created. We must prepare to download the resource. First, we will attemt to detect the status code for the resource.
-
-            // Open a stream to the resource.
-            $fp = fopen($_POST['URI_array'][$counter],"rb");
-
+            if( ini_get('allow_url_fopen') == 1)
+            {
+              // Open a stream to the resource.
+              $fp = fopen($_POST['URI_array'][$counter],"rb");
+            }
+            else
+            {
+              $fp = curl_init($_POST['URI_array'][$counter]);
+            }
             // Check to see if the resource was opened.
             if (!$fp) {
 
@@ -1725,12 +1758,25 @@
                 }
 
             } else {
-
+ 
                 // Obtain header info if possible.
                 if (function_exists('stream_get_meta_data')) {
 
-                    // Store header data in $header.
-                    $header = stream_get_meta_data($fp);
+                    if( ini_get('allow_url_fopen') == 1)
+                    {
+                      $header = stream_get_meta_data($fp);
+                    }
+                    else
+                    {
+                      // 模擬 stream_get_meta_data
+                      curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
+                      $content = curl_exec($fp);
+                      $data =   curl_getinfo($fp);
+
+                      $header['wrapper_data'][] = "$data[http_code]";
+                      $header['wrapper_data'][] = 'content-type: '.$data['content_type'];
+                      $header['wrapper_data'][] = 'content-length: '.$data['download_content_length'];
+                    }
 
                     // If data was returned, test it.
                     if($header) {
@@ -1844,20 +1890,28 @@
 
                 } else {
 
-                    // Initialize the $content variable.
-                    $content = '';
-
-                    // The write file has been created and is writeable.  Let's get the content from the URI.
-                    while (!feof($fp)) {
-
-                        // Read the data into $content in 8KB chunks.
-                        $content .= fread($fp,8192);
-
+                    
+                    if( ini_get('allow_url_fopen') == 1)
+                    {
+                      // Initialize the $content variable.
+                      $content = '';
+                      // The write file has been created and is writeable.  Let's get the content from the URI.
+                      while (!feof($fp)) {
+  
+                          // Read the data into $content in 8KB chunks.
+                          $content .= fread($fp,8192);
+  
+                      }
                     }
-
+                    if( ini_get('allow_url_fopen') == 1)
+                    {
                     // Close the file pointer now that we are done reading it.
-                    fclose($fp);
-
+                      fclose($fp);
+                    }
+                    else
+                    {
+                      curl_close($ch); 
+                    }
                     // Open the temp file for writing.
                     $fpw = fopen($path_to_image, "wb");
 
