我想问题是当服务器中的代码正在执行时,文件是在你的机器上@'.'D:\images\photo-b4.jpg';
而不是从你的机器上归档的
在本地主机的情况下,您的机器和服务器是相同的,因此它会找到物理上位于@'.'D:\images\photo-b4.jpg';
如果您要上传什么文件,您需要在运行时发出整个 Web 表单请求并将其发布到服务器
尝试这样的事情:-它不是您需要相应更改的确切代码
$requestparameters["title"] = $filetitle;
$content = file_get_contents($_FILES['uploadingfile']['tmp_name']);
$filefieldname = (array_keys($_FILES));
$delimiter = '-------------' . uniqid();
$filefields = array(
'file1' => array(
'name' => $_FILES['uploadingfile']['name'],
'type' => $_FILES['uploadingfile']['type'],
'content' => $content),
);
$data = '';
foreach ($requestparameters as $name => $value) {
$data .= "--" . $delimiter . "\r\n";
$data .= 'Content-Disposition: form-data; name="' . $name . '";' . "\r\n\r\n";
// note: double endline
$data .= $value . "\r\n";
}
foreach ($filefields as $name => $file) {
$data .= "--" . $delimiter . "\r\n";
// "filename" attribute is not essential; server-side scripts may use it
$data .= 'Content-Disposition: form-data; name="' . $filefieldname['0'] . '";' .
' filename="' . $file['name'] . '"' . "\r\n";
// this is, again, informative only; good practice to include though
$data .= 'Content-Type: ' . $file['type'] . "\r\n";
// this endline must be here to indicate end of headers
$data .= "\r\n";
// the file itself (note: there's no encoding of any kind)
$data .= $file['content'];
}
$data .= "\r\n"."--" . $delimiter . "--\r\n";
$str = $data;
// set up cURL
$ch=curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array( // we need to send these two headers
'Content-Type: multipart/form-data; boundary='.$delimiter,
'Content-Length: '.strlen($str)
),
CURLOPT_POSTFIELDS => $data,
));
$ress = curl_exec($ch);
curl_close($ch);