i want send form with input:file for send information and upload some (2 to 10) files. when form submit information send to main host (form:action) and i do some process on data and i want upload sending files to another host without uploading in main host, so i researching and find CURL way to sending this part for one PHP file in other host and uploading files on that host, and i fund 3 way to send files: (i used for function to detect all send files and user $i for indexes and put in array before send)

1: just use real path :

'@'.realpath($_FILES['attach']['tmp_name'][$i]);

2: use file create :

curl_file_create(realpath($_FILES['attach']['tmp_name'][$i]),mime_content_type($_FILES['attach']['tmp_name'][$i]),basename($_FILES['attach']['tmp_name'][$i]));

3: use CurlFile :

new CurlFile(realpath($_FILES['attach']['tmp_name'][$i]),mime_content_type($_FILES['attach']['tmp_name'][$i]),basename($_FILES['attach']['tmp_name'][$i]));

but it is not working and destroy my files to send because i use this code in another server for testing how this works but it is not working

this code is in another server (target of CURL) :

for($i=0;$i<count($_FILES['attachment']['tmp_name']);$i++){
$tmp_name=$_FILES['attachment']['tmp_name'][$i];
$name=$_FILES['attachment']['name'][$i];
$size=$_FILES['attachment']['size'][$i];
$EXTENSION=pathinfo($_FILES['attachment']['tmp_name'][$i],PATHINFO_EXTENSION);
/*uploading files and insert this information to database ...*/
}

but in all 3 way i said, the extension be "tmp" not real extension of my send files; so how i can fix this ?

WAY 1 :

for($i=0;$i<count($_FILES['attachment']['tmp_name']);$i++){
$PostItems['attachment['.$i.']']=new CurlFile(realpath($_FILES['attachment']['tmp_name'][$i]),mime_content_type($_FILES['attachment']['tmp_name'][$i]),basename($_FILES['attachment']['tmp_name'][$i]));
}

WAY 2 :

for($i=0;$i<count($_FILES['attachment']['tmp_name']);$i++){
$PostItems['attachment['.$i.']']=curl_file_create($_FILES['attachment']['tmp_name'][$i]),mime_content_type($_FILES['attachment']['tmp_name'][$i]),basename($_FILES['attachment']['tmp_name'][$i]));
}

WAY 3 :

for($i=0;$i<count($_FILES['attachment']['tmp_name']);$i++){
$PostItems['attachment['.$i.']']='@'.realpath($_FILES['attachment']['tmp_name'][$i]);
}

$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$TargetURL);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_VERBOSE,0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$PostItems);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result=curl_exec($ch);curl_close($ch);
echo $result;

i expect in another server (target of curl) i get information from sending files but in all ways the extension of files to be "tmp" and name of files all of them to be "php1234.tmp" and not real my files name

0 Answers