我想使用 PHP 上传文件 DICOM

I want upload file DICOM using PHP

请查看下面我用来将文件上传到 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 )

您没有上传任何内容。自 PHP 5.5 以来,不鼓励使用 @ 方案上传文件,自 PHP 5.6 起默认禁用(使用 CURLOPT_SAFE_UPLOAD 选项),自 [=] 起完全删除22=]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);
    }

(我很确定不需要真实路径,它只会减慢代码速度)