]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15991 - allow curl library to POST files by integrating with stored_file object.
authormjollnir_ <mjollnir_>
Sat, 9 Aug 2008 13:35:33 +0000 (13:35 +0000)
committermjollnir_ <mjollnir_>
Sat, 9 Aug 2008 13:35:33 +0000 (13:35 +0000)
lib/file/stored_file.php
lib/filelib.php

index bbc0dfb856aff9f5fb006c5773cf69ae734fe794..d42061286bf9e2b50d7a571a3dc5410df1538181 100644 (file)
@@ -49,6 +49,16 @@ class stored_file {
         return "$filedir/$l1/$l2/$l3/$contenthash";
     }
 
+    /**
+    * adds this file path to a curl request (POST only)
+    *
+    * @param curl $curlrequest the curl request object
+    * @param string $key what key to use in the POST request
+    */
+    public function add_to_curl_request(&$curlrequest, $key) {
+        $curlrequest->_tmp_file_post_params[$key] = '@' . $this->get_content_file_location();
+    }
+
     /**
      * Returns file handle - read only mode, no writing allowed into pool files!
      * @return file handle
index 10d2684d8a31b34496fdce0225790dee864e6671..c90b7fc344b82ef4598c84eff03f709a498bcdf3 100644 (file)
@@ -1635,7 +1635,16 @@ class curl {
      */
     public function post($url, $params = array(), $options = array()){
         $options['CURLOPT_POST']       = 1;
-        $options['CURLOPT_POSTFIELDS'] = $params;
+        $this->_tmp_file_post_params = array();
+        foreach ($params as $key => $value) {
+            if ($value instanceof stored_file) {
+                $value->add_to_curl_request($this, $key);
+            } else {
+                $this->_tmp_file_post_params[$key] = $value;
+            }
+        }
+        $options['CURLOPT_POSTFIELDS'] = $this->_tmp_file_post_params;
+        unset($this->_tmp_file_post_params);
         return $this->request($url, $options);
     }