Upload e download di file con curl

upload

<?php
if (isset($_POST['MAX_FILE_SIZE'])){

$file=$_FILES['userfile']['tmp_name'];
$ch = curl_init('http://myurl.com/recieve_posted.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>"@$file",'testkey'=>'testvalue',));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
curl_close($ch);
print
"$postResult";
}
?>

 

 

download
<?php
$url = ‘http://www.example.com/a-large-file.zip’;
$path = ‘/path/to/a-large-file.zip’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
file_put_contents($path, $data);
?>