使用php的crul函數進行上傳

<?php
$target_url = "http://服務器";
$file_name_with_full_path = "本地文件路徑/var/www/......";
if (function_exists('curl_file_create')) { // php 5.5+
    $cFile = curl_file_create($file_name_with_full_path);
} else { //
    $cFile = '@' . realpath($file_name_with_full_path);
}
$post = array(
    'extra_info' => 'PHP文件上傳',
    'file_contents' => $cFile
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章