--- private_upload.original	2007-12-16 15:29:57.611270000 -0800
+++ private_upload.module	2007-12-16 19:39:45.242410000 -0800
@@ -75,6 +75,61 @@
   return $items;
 }
 
+/**
+ * private_upload_is_publicly_accessible()
+ *
+ * cURL used as get_headers() fails when allow_url_fopen disabled
+ *
+ * Status codes checked:
+ * 
+ *   200 OK:    The request has succeeded.
+ *   302 Found: The requested resource resides temporarily under a different URI
+ *   See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
+ *
+ * @param $url: url to check if publicly accessible
+ * @return boolean true if publicly accessible, else false
+ */
+function private_upload_is_publicly_accessible($url) {
+ 
+  $return_val          = FALSE; 
+  $socket_open_timeout = 30;
+  $read_data_timeout   = 10;
+  $max_chunk           = 1024;
+  $status_codes        = array("200","302"); // see function header for code details
+  
+  // parse and open a socket to the requested resource
+  $url_info=parse_url($url); 
+  $port=isset($url_info['port']) ? $url_info['port'] : 80;
+  $fp=fsockopen($url_info['host'], $port, $errno, $errstr, $socket_timeout);
+
+  if(!$fp) return FALSE;
+
+  stream_set_timeout($fp, $read_data_timeout);
+
+  // Request resource headers
+  $head = "HEAD ".@$url_info['path']."?".@$url_info['query'];
+  $head .= " HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";
+  fputs($fp, $head);
+
+  // Read resource headers
+  if($header=trim(fgets($fp, $max_chunk))) {
+    $header_array = explode(': ',$header);
+
+    // foreach implemented as while loop to allow for short-circuiting. See:
+    // http://us.php.net/manual/en/control-structures.foreach.php   
+    while((list(, $status_code)= each($status_codes)) && $return_val==FALSE) {
+      // Header type in header_array[0]
+      if( strstr($header_array[0], $status_code)) {
+        $return_val = TRUE; // publicly accessible status code returned
+      }
+    } 
+  }
+
+  fclose($fp);
+
+  // default
+  return $return_val;
+}
 
 /**
  * hook_requrements().
@@ -124,10 +179,9 @@
   }
   closedir( $d );
   
-  if( $afile && function_exists('get_headers') ) { // found one, see if it is accessable
+  if ( $afile ) { // found one, see if it is accessible
     $url = $GLOBALS['base_url'] .'/'. $private_path .'/' . $afile;
-    $headers = get_headers( $url );
-    if( strstr($headers[0], '200') || strstr($headers[0], '302') ) {
+    if ( private_upload_is_publicly_accessible( $url )) {
       $requirements['private_upload_readable'] = array(
         'title' => t('Private Upload'),
         'severity' => REQUIREMENT_WARNING,
