CURLOPT_INFILE
, но она это делает методом put.$curl = curl_init('http://localhost/upload.php');
$file = fopen($name, 'rb');
// curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type" => "multipart/form-data"));
// curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_PUT, TRUE);
curl_setopt($curl, CURLOPT_INFILE, $file);
curl_setopt($curl, CURLOPT_READFUNCTION, function($curl, $in, $max){ return fread($in, $max); });
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$ret = curl_exec($curl);
if(curl_errno($curl)){
echo 'CURL error:['. curl_errno($curl). '] '. curl_error($curl) .'<br>';
die();
}
fclose($file);
curl_close($curl);
echo $ret;
function uploadFile($desource, $source, $name='file.txt', $field='file'){
$bodyend = $body = $head = $out = '';
$boundary = '-------------'. uniqid();
// $cipher = new \phpseclib3\Crypt\RC4();
// $cipher->setKey('qwertyuiop');
$source = parse_url($source);
$source['scheme'] = $source['scheme'] == 'http' ? '' : $source['scheme'];
$source['scheme'] = ($source['scheme'] == 'https' ? 'ssl' : $source['scheme']) . ($source['scheme'] ? '://' : '');
$source['port'] = $source['port'] ?? ($source['scheme'] == 'ssl://' ? 443 : 80);
$source['path'] = ($source['path'] ?? '/') . ($source['query'] ? ('?'. $source['query']) : '');
$size = filesize($desource);
$file = fopen($desource, 'rb');
$server = fsockopen("{$source['scheme']}{$source['host']}", $source['port']);
$body .= "--$boundary\r\n";
$body .= "Content-Disposition: form-data; name=\"$field\"; filename=\"$name\"\r\n";
$body .= "Content-Type: application/octet-stream\r\n\r\n";
$bodyend .= "\r\n";
$bodyend .= "--$boundary--\r\n\r\n";
$head .= "POST {$source['path']} HTTP/1.1\r\n";
$head .= "Host: {$source['host']}\r\n";
$head .= "Content-Type: multipart/form-data; boundary=$boundary\r\n";
$head .= 'Content-length: '. (strlen($body) + $size + strlen($bodyend)) ."\r\n";
$head .= "\r\n";
fputs($server, $head);
fputs($server, $body);
while(!feof($file)){
// fputs($server, $cipher->encrypt(fread($file, 16384)));
fputs($server, fread($file, 16384));
}
fputs($server, $bodyend);
while(!feof($server)) $out .= fread($server, 16384);
fclose($server);
return $out;
}