2010-10-15 23 views
0

Comment devrais-je aller en soumettant un fichier qui dans le même répertoire que ce script à l'intérieur du $data. La fonction ci-dessous est ce que j'utilise actuellement. Si vous trouvez des bugs dans le code actuel, dites-le moi aussi.PHP Curl télécharger le fichier par l'intermédiaire des données de poste

function post_data($site,$data){ 
    $datapost = curl_init(); 
$headers = array("Expect:"); 
    curl_setopt($datapost, CURLOPT_URL, $site); 
curl_setopt($datapost, CURLOPT_TIMEOUT, 40000); 
    curl_setopt($datapost, CURLOPT_HEADER, TRUE); 
curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
    curl_setopt($datapost, CURLOPT_POST, TRUE); 
    curl_setopt($datapost, CURLOPT_POSTFIELDS, $data); 
    curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt"); 
    ob_start(); 
    return curl_exec ($datapost); 
    ob_end_clean(); 
    curl_close ($datapost); 
    unset($datapost);  
} 

Répondre

-1

Votre premier problème est que votre compter sur CURL, Just kidding, mais voici une autre façon à la peau ce chat:

// prepare post headers 
$opts = array(
    'http' => 
    array(
     'method' => 'POST', 
     'charset' => 'utf-8', 
     'timeout' => '60', // must be set for error handling 
     'content' => 'post data can be inserted here', // this can be a file 
     )); 
$context = @stream_context_create($opts); 
// send post data and store response data 
$response = @file_get_contents('http://www.example.org/file.php', 
    false, $context); 

// using this posting method one does not have to rely on any external libraries 
+0

Can ... 'contenu' => ... être un chemin? Ou est-ce ** que ** doit être le contenu du fichier? – Pepster