Skip to content

Instantly share code, notes, and snippets.

@shierw
Created June 14, 2017 02:27
Show Gist options
  • Save shierw/328d6e014296ddecb1c669920ea13283 to your computer and use it in GitHub Desktop.
Save shierw/328d6e014296ddecb1c669920ea13283 to your computer and use it in GitHub Desktop.
<?php
$uploadUrl = 'http://test.com/upload.php';
// 转发从其它客户端上传的文件,name="file"
upload_file($uploadUrl, realpath($_FILES['file']['tmp_name']), $_FILES['file']['type'], $_FILES['file']['name']);
/**
* curl上传文件
*/
function upload_file($url, $path, $type, $filename){
$data = array(
'adviceimg'=>'@'.$path.';type='.$type.';filename='.$filename,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return_data = curl_exec($ch);
curl_close($ch);
echo $return_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment