?上传超大文件设置php.ini
upload_max_filesize = 50000M
nginx.conf
client_max_body_size 80000m;
public function uploadImage1(Request $request)
{
set_time_limit(0);
$curl_url = config('public.HOST_COMPUTER');
$file = $_FILES['file'];
if ($file['error'] != 0) {
// 文件上传错误
var_dump($file);
die;
}
$params = [
'test' => 'test' // 其他普通参数 test
];
if (class_exists('\CURLFile')) {
//php 5.5以上的用法
$params['file'] = new \CURLFile(realpath($file['tmp_name']), $file['type'], $file['name']);
} else {
$params['file'] = '@' . realpath($file['tmp_name']) . ";type=" . $file['type'] . ";filename=" . $file['name'];
}
$curl_result = json_decode($this->curlPost($curl_url, $params), true);
showMsg(200, "",$curl_result);
}
// 发起请求携带文件数据流
private function curlPost($url, $data,$headers = array())
{
$curl = curl_init();
if (class_exists('\CURLFile')) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
//$data = array('file' => new \CURLFile(realpath($path)));//>=5.5
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
}
//$data = array('file' => '@' . realpath($path));//<=5.5
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1 );
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$result = curl_exec($curl);
$error = curl_error($curl);
//var_dump($error);
curl_close($curl);
return $result;
}
|