请查看以下我用于将文件上传到orthanc的代码。我不确定此错误是来自orthanc配置还是由于CURL
$total = count($_FILES['file']['name']);
$tmp_name = array();
for ($i = 0; $i < $total; $i++) {
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
array_push($tmp_name, $tmpFilePath);
}
$postfields = array();
foreach ($tmp_name as $index => $file) {
$file = '@' . realpath($file);
$postfields["file_$index"] = $file;
}
$url = 'http://localhost/instances';
$postfields = $postfields;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); //require php 5.6^
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
//print curl_error($ch);
}
curl_close($ch);
$json = json_decode($postResult, true);
print_r($json);
这是我遇到的错误。
Array ( [Details] => Cannot parse an invalid DICOM file (size: 28 bytes) [HttpError] => Bad Request [HttpStatus] => 400 [Message] => Bad file format [Method] => POST [OrthancError] => Bad file format [OrthancStatus] => 15 [Uri] => /instances )
答案 0 :(得分:2)
您没有上传任何内容。自PHP 5.5起,不建议使用@
上传文件的方案,自PHP 5.6起默认禁用(使用CURLOPT_SAFE_UPLOAD
选项),自PHP 7.0起已完全删除
替换
foreach ($tmp_name as $index => $file) {
$file = '@' . realpath($file);
$postfields["file_$index"] = $file;
}
使用
foreach ($tmp_name as $index => $file) {
$file = realpath($file);
$postfields["file_{$index}"] = new CURLFile($file);
}
(而且我很确定不需要realpath,它只是降低了代码的速度)