Ben böyle bir form var:
<form method="POST" action="i.php" enctype="multipart/form-data">
<input type="text" name="field1">
<input type="text" name="field2">
<input type="file" name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
<input type="submit">
</form>
Sayfada ben zaten:
$URL = 'http://somewhere.com/catch.php';
$fields = array('field1'=>urlencode($_POST['field1'), 'field2'=>urlencode($_POST['field2'));
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; };
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
That works to post the field1 & 2 fields. Is it possible to include the file in that curl process somehow? How would I do that? I'm assuming I have to do more than just encode the file value.
Yani aşağıdaki güncelleştirilmiş SimpleCoders 'cevap dayalı:
$URL = 'http://somewhere.com/catch.php';
$fields = array('field1'=>urlencode($_POST['field1'), 'field2'=>urlencode($_POST['field2'), 'files'=>'@'. $_FILES['file']['tmp_name']);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; };
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
Tamam hangi mesajlar ama sonra catch.php benim sonuçlanan $ _FILES dizi boştur. http://www.php.net/manual/en/function.curl-setopt.php Bu işe gerektiği üzerinde Örnek # 2 accoring.
Ben iki farklı etki bu yapıyorum ... bu bir sorun olabilir?