//index file
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" value="Post"/>
</form>
<?php
if(isset($_FILES['image']['tmp_name'])){
$ch = curl_init();
$cfile =new CURLFile($_FILES['image']['tmp_name'],$_FILES['image']['type'],$_FILES['image']['name']);
$data = array('myimage' => $cfile);
curl_setopt($ch,CURLOPT_URL,"http://localhost/curl/send_file_to_server/uploads.php");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
$response = curl_exec($ch);
if($response == true){
echo "File Posted";
}
else{
echo "Error: ".curl_error($ch);
}
}
?>
//uploads file
<?php
if(isset($_FILES['myimage']['tmp_name'])){
$path = "uploads/".$_FILES['myimage']['tmp_name'];
move_uploaded_file($_FILES['myimage']['name'],$path);
}
?>
Here I want to store an image of index.php into the uploads.php. I am using curl method of php.The file print that file posted but not store in the uploads folder.