PHP - Télécharger un fichier image vers un autre domaine avec CURL

J'ai deux domaine, à titre d'exemple site1.loc et site2.loc. Dans site1.loc j'ai un fichier de formulaire php comme ceci:

<?php
$c_name = "";
$c_phone = "";

if($_SERVER['REQUEST_METHOD']=="POST"){

    $c_name = $_POST['c_name'];
    $c_phone = $_POST['c_phone'];
    $c_pic = $_FILES['c_pic']['name']; //Image file

        //submit target URL
        $url = 'http://site2.loc/handler.php';

        $fields = array(
           'field1'=>$c_name,
           'field2'=>$c_phone,
           'field3'=>$c_pic
        );

        $postvars='';
        $sep='';
        foreach($fields as $key=>$value) 
        { 
           $postvars.= $sep.urlencode($key).'='.urlencode($value); 
           $sep='&'; 
        }


        //open connection
        $ch = curl_init();

        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_POST,count($fields));
        curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);

        //execute post
        $result = curl_exec($ch);

        if(curl_errno($ch)) {
            echo 'Error: ' . curl_error($ch);
        }
        else {
            echo $result;
        }

        //close connection
        curl_close($ch);

}


echo '
<form action="" method="post" enctype="multipart/form-data">
    Name : <input type="text" name="c_name" value="'.$c_name.'" /> <br />
    Phone : <input type="text" name="c_phone" value="'.$c_phone.'" /> <br />
    Image : <input type="file" name="c_pic" /> <br />
    <input type="submit" />
</form>
    ';
?>

et handler.php dans site2.loc comme ceci:

<?php
ob_start();
if (!isset($_SESSION)) { session_start(); }

    //CONNECT TO DB
    $db_con = mysql_connect("localhost", "root", "root");//or die("Could not connect to db.");
    if(!mysql_select_db("site2",$db_con)) die("No database selected.");

    //POST
    if(isset($_POST)){
        $c_name = $_POST['field1'];
        $c_phone = $_POST['field2'];    
        $c_pic = $_POST['field3'];  

        //UPLOAD FILE
        /* UPLOAD IMAGE CODE HERE */

        //INSERT TO DB
        if(mysql_query("INSERT INTO kontak (nama, telpon) VALUES ('$c_name','$c_phone')")){
            echo "INSERT SUCCESS";
        } else {
            echo "INSERT FAILED";
        }
    }

?>

Ce script s'exécute bien pour stocker les données de la base de données, mais ne peut pas pour télécharger un fichier image. Quelqu'un peut-il m'aider à modifier les scripts ci-dessus afin de télécharger un fichier image?

Grâce avant.

OriginalL'auteur Fredy | 2013-05-16