| 73 |
* @param $path |
* @param $path |
| 74 |
*/ |
*/ |
| 75 |
function fileapi_driver_s3_mkdir($settings, $path) { |
function fileapi_driver_s3_mkdir($settings, $path) { |
| 76 |
|
// there are technically no directories, so we can safely do |
| 77 |
|
// nothing here. |
| 78 |
|
return TRUE; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
/** |
/** |
| 83 |
* remove a directory using standard php functions |
* remove a directory using standard php functions |
| 84 |
* @param $path |
* @param $path |
| 85 |
*/ |
*/ |
| 86 |
|
|
| 87 |
function fileapi_driver_s3_rmdir($settings, $path) { |
function fileapi_driver_s3_rmdir($settings, $path) { |
| 88 |
|
// there are technically no directories. |
| 89 |
|
// so we can test is there is a file in the 'directory' and return false here. |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
|
|
| 96 |
*/ |
*/ |
| 97 |
function fileapi_driver_s3_remove($settings, $path) { |
function fileapi_driver_s3_remove($settings, $path) { |
| 98 |
clearstatcache(); |
clearstatcache(); |
| 99 |
|
|
| 100 |
} |
} |
| 101 |
|
|
| 102 |
/** |
/** |
| 105 |
* @param $dst |
* @param $dst |
| 106 |
*/ |
*/ |
| 107 |
function fileapi_driver_s3_copy($settings, $src, $dst) { |
function fileapi_driver_s3_copy($settings, $src, $dst) { |
| 108 |
|
|
| 109 |
} |
} |
| 110 |
|
|
| 111 |
/** |
/** |
| 114 |
* @param $dst |
* @param $dst |
| 115 |
*/ |
*/ |
| 116 |
function fileapi_driver_s3_move($settings, $src, $dst) { |
function fileapi_driver_s3_move($settings, $src, $dst) { |
| 117 |
|
|
| 118 |
} |
} |
| 119 |
|
|
| 120 |
/** |
/** |
| 135 |
$headers = array(); |
$headers = array(); |
| 136 |
$headers['Content-Type'] = 'text/plain'; |
$headers['Content-Type'] = 'text/plain'; |
| 137 |
$body = file_get_contents($tmp); |
$body = file_get_contents($tmp); |
| 138 |
_s3_request('PUT', $path, $settings, array(), $body); |
s3_request('PUT', $path, $settings, array(), $body); |
| 139 |
} |
unlink($tmp); |
|
|
|
|
|
|
|
function _s3_request($method, $resource, $settings, $headers=array(), $amzheaders=array(), $body= '') { |
|
|
|
|
|
$url = $settings['s3 url'] . $settings['bucket']; |
|
|
|
|
|
// Set date to proper format for S3. |
|
|
$headers['Date'] = gmdate(DATE_RFC822); |
|
|
$headers['Authorization'] = 'AWS '. $settings['awsID'] .':'. $signature; |
|
|
|
|
|
// Build S3 authorization hash. |
|
|
$auth_string = $method ."\n\n". $headers['Content-type'] ."\n"; |
|
|
$auth_string .= $headers['Date'] ."\n". implode("\n",$amzheaders) ."\n". $resource; |
|
|
$signature = hex2b64(s3_hmac_sha1($settings['awsSecret'], $auth_string)); |
|
|
|
|
|
// Set date to proper format for S3. |
|
|
$headers['Date'] = gmdate(DATE_RFC822); |
|
|
$headers['Authorization'] = 'AWS '. $settings['awsID'] .':'. $signature; |
|
|
|
|
|
$result = drupal_http_request($url .'/'. $resource, array_merge($headers, $amzheaders), $method, $body); |
|
|
drupal_set_message('<pre>'. print_r($result, TRUE) .'</pre>'); |
|
|
|
|
| 140 |
} |
} |
| 141 |
|
|
| 142 |
|
|
| 159 |
* and our support target is 4.3.0. |
* and our support target is 4.3.0. |
| 160 |
*/ |
*/ |
| 161 |
function fileapi_driver_s3_fileread($settings, $path) { |
function fileapi_driver_s3_fileread($settings, $path) { |
| 162 |
|
return s3_request('GET', $path, $settings); |
| 163 |
} |
} |
| 164 |
|
|
| 165 |
function fileapi_driver_s3_filewrite($settings, $path, $data) { |
function fileapi_driver_s3_filewrite($settings, $path, $data) { |
| 166 |
|
$headers = array('Content-Type' => 'text/plain'); |
| 167 |
|
s3_request('PUT', $path, $settings, array(), $data); |
| 168 |
} |
} |
| 169 |
|
|
| 170 |
|
|
| 171 |
|
function s3_request($method, $resource, $settings, $headers=array(), $amzheaders=array(), $body= '') { |
| 172 |
|
$url = $settings['s3 url'] . $settings['bucket']; |
| 173 |
|
|
| 174 |
|
// Set date to proper format for S3. |
| 175 |
|
$headers['Date'] = gmdate(DATE_RFC822); |
| 176 |
|
$headers['Authorization'] = 'AWS '. $settings['awsID'] .':'. $signature; |
| 177 |
|
|
| 178 |
|
// Build S3 authorization hash. |
| 179 |
|
$auth_string = $method ."\n\n". $headers['Content-type'] ."\n"; |
| 180 |
|
$auth_string .= $headers['Date'] ."\n". implode("\n",$amzheaders) ."\n". $resource; |
| 181 |
|
$signature = hex2b64(s3_hmac_sha1($settings['awsSecret'], $auth_string)); |
| 182 |
|
|
| 183 |
|
// Set date to proper format for S3. |
| 184 |
|
$headers['Date'] = gmdate(DATE_RFC822); |
| 185 |
|
$headers['Authorization'] = 'AWS '. $settings['awsID'] .':'. $signature; |
| 186 |
|
|
| 187 |
|
$result = drupal_http_request($url .'/'. $resource, array_merge($headers, $amzheaders), $method, $body); |
| 188 |
|
drupal_set_message('<pre>'. print_r($result, TRUE) .'</pre>'); |
| 189 |
|
} |
| 190 |
|
|
| 191 |
/** |
/** |
| 192 |
* Generate an sha1 signed hash of a string. |
* Generate an sha1 signed hash of a string. |