$temp_path = 'files/tasks/_temp/';
File::isDirectory($temp_path) or File::makeDirectory($temp_path, 0777, true, true);
$temp_path_local = $temp_path . Input::get('task_id') . "/";
$s3 = AWS::get('s3');
foreach (json_decode(Input::get('values')) as $file_id) {
$file = TaskFile::find($file_id);
$downloadPath = $temp_path_local . $file->original_filename;
if (!file_exists($temp_path_local)) {
mkdir($temp_path_local, 0777, true);
}
$fp = fopen ($downloadPath, 'w+');
$ch = curl_init($s3->getObjectUrl(Config::get('app.tasks_bucketname'), $file->s3_key));
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
}