註:PHP 5 >= 5.5.0


<?php

/* http://example.com/upload.php:
<?php var_dump($_FILES); ?>
*/

// 創建一個 cURL 句柄
$ch = curl_init('http://example.com/upload.php');

// 創建一個 CURLFile 對象
$cfile = curl_file_create('cats.jpg','image/jpeg','test_name');

// 設置 POST 數據
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

// 執行句柄
curl_exec($ch);
?>


以上例程會輸出:
array(1) {
["test_file"]=>
array(5) {
["name"]=>
string(9) "test_name"
["type"]=>
string(10) "image/jpeg"
["tmp_name"]=>
string(14) "/tmp/phpPC9Kbx"
["error"]=>
int(0)
["size"]=>
int(46334)
}
}

 

 

 

arrow
arrow
    全站熱搜

    stockwfj3 發表在 痞客邦 留言(0) 人氣()