Navigation Menu

Skip to content

Commit

Permalink
MDL-15991 - allow curl library to POST files by integrating with stor…
Browse files Browse the repository at this point in the history
…ed_file object.
  • Loading branch information
mjollnir_ committed Aug 9, 2008
1 parent ebcac6c commit 5035a8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/file/stored_file.php
Expand Up @@ -49,6 +49,16 @@ protected function get_content_file_location() {
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
Expand Down
11 changes: 10 additions & 1 deletion lib/filelib.php
Expand Up @@ -1635,7 +1635,16 @@ public function head($url, $options = array()){
*/
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);
}

Expand Down

0 comments on commit 5035a8b

Please sign in to comment.