21,882
社区成员
发帖
与我相关
我的任务
分享
$ch = curl_init();
$filePath = __DIR__.'/1.jpg';
$data = ['name' => 'Foo', 'file' => '@' . $filePath];
if (class_exists('\CURLFile')) {
$data['file'] = new \CURLFile(realpath($filePath));
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, FALSE);
}
}
curl_setopt($ch, CURLOPT_URL, 'http://localhost/file/file.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
//$info=curl_getinfo($ch);
curl_close($ch);
file.php
echo '<pre>';
print_r($_FILES['file']);
看看行不