Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想上传文件DICOM使用PHP_Php_Curl_File Upload_Dicom - Fatal编程技术网

我想上传文件DICOM使用PHP

我想上传文件DICOM使用PHP,php,curl,file-upload,dicom,Php,Curl,File Upload,Dicom,请看下面的代码,我用它上传文件到orthanc。我不确定这个错误是来自orthanc配置还是因为CURL $total = count($_FILES['file']['name']); $tmp_name = array(); for ($i = 0; $i < $total; $i++) { $tmpFilePath = $_FILES['file']['tmp_name'][$i]; ar

请看下面的代码,我用它上传文件到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);
$total=count($_FILES['file']['name']);
$tmp_name=array();
对于($i=0;$i<$total;$i++){
$tmpFilePath=$\u文件['file']['tmp\u名称][$i];
数组推送($tmp\u名称,$tmpFilePath);
}
$postfields=array();
foreach($tmp_名称为$index=>$file){
$file='@'.realpath($file);
$postfields[“文件\索引”]=$file;
}
$url='1http://localhost/instances';
$postfields=$postfields;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_SAFE_UPLOAD,false)//需要PHP5.6^
curl_setopt($ch,CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$postResult=curl\u exec($ch);
if(旋度误差($ch)){
//打印卷曲错误($ch);
}
卷曲关闭($ch);
$json=json_decode($postResult,true);
打印(json);
这是我得到的错误


Array([Details]=>无法解析无效的DICOM文件(大小:28字节)[HttpError]=>错误请求[HttpStatus]=>400[Message]=>错误文件格式[Method]=>POST[orhancerror]=>错误文件格式[orhancstatus]=>15[Uri]=>/实例)

您没有上载任何内容。自PHP5.5起,上传文件的
@
方案就被禁止,自PHP5.6起默认禁用(使用
CURLOPT_SAFE_upload
选项),自PHP7.0起完全删除

替换

    foreach ($tmp_name as $index => $file) {
        $file = '@' . realpath($file);
        $postfields["file_$index"] = $file;
    }


(我很确定realpath不是必需的,它只是降低了代码的速度)

似乎“DICOM文件”已损坏或扩展错误不,我已下载了新的DICOM文件。
    foreach ($tmp_name as $index => $file) {
        $file = realpath($file);
        $postfields["file_{$index}"] = new CURLFile($file);
    }