function filefield_source_remote_curl_write in FileField Sources 6
Same name and namespace in other branches
- 7 sources/remote.inc \filefield_source_remote_curl_write()
cURL write function to save the file to disk. Also updates progress bar.
1 string reference to 'filefield_source_remote_curl_write'
- filefield_source_remote_value in sources/
remote.inc - A #filefield_value_callback function.
File
- sources/
remote.inc, line 293 - A FileField extension to allow referencing of existing files.
Code
function filefield_source_remote_curl_write(&$ch, $data) {
$progress_update = 0;
$options = filefield_source_remote_get_transfer_options();
// Get the current progress and update the progress value.
// Only update every 64KB to reduce cache_set calls. cURL usually writes
// in 16KB chunks.
if (curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD) / 65536 > $progress_update) {
$progress_update++;
$progress = array(
'current' => curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD),
'total' => curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD),
);
// Set a cache so that we can retrieve this value from the progress bar.
$cid = 'filefield_transfer:' . session_id() . ':' . $options['key'];
if ($progress['current'] != $progress['total']) {
cache_set($cid, $progress, 'cache', time() + 300);
}
else {
cache_clear_all($cid, 'cache');
}
}
$data_length = 0;
if ($fp = @fopen($options['filepath'], 'a')) {
fwrite($fp, $data);
fclose($fp);
$data_length = strlen($data);
}
return $data_length;
}