I use cURL to transfer image files from one server to another using PHP. This is my cURL code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'http://' . $server_data['hostname'] . '.localhost/transfer.php');
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
'upload[]' => '@' . $tmp_uploads . $filename,
'upload[]' => '@' . $tmp_uploads . $thumbname,
'salt' => 'q8;EmT(Vx*Aa`fkHX:up^WD^^b#<Lm:Q'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$resp = curl_exec($ch);
This is the code in the transfer.php file on the server that I upload:
if($_FILES && $_POST['salt'] == 'q8;EmT(Vx*Aa`fkHX:up^WD^^b#<Lm:Q')
{
foreach($_FILES['upload']['error'] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
move_uploaded_file($_FILES['upload']['tmp_name'][$key], $_FILES['upload']['name'][$key]);
}
}
}
Everything seems to work, except for one small logical error. Only one file is saved on the server to which I transfer. This is probably due to the fact that I call both images upload[]in my array of message fields, but I do not know how to do this. I am trying to imitate this:
<input type="file" name="upload[]" />
<input type="file" name="upload[]" />
Does anyone know how I can make this work? Thank!
source
share