我正在尝试使用 VirusTotal 的公共(public) API 来扫描文件。这是我的代码:
$post_url = 'https://www.virustotal.com/vtapi/v2/file/scan';
$filemime = exec("file -b --mime-type '$file_to_scan'");
$post = array('apikey' => $virustotal_api_key, 'file' => '@' . realpath($file_to_scan) . ';type=' . $filemime . ';filename=' . $name);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$post_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER,array('Expect:'));
$api_reply = curl_exec($ch);
curl_close($ch);
$api_reply_array = json_decode($api_reply, true);
每当我运行这段代码时,我都会收到以下错误:
[response_code] => 0
[verbose_msg] => Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation
我花了好几个小时试图解决这个问题,但就是行不通。谁能指出我正确的方向?
这是上面代码中$post
的print_r
:
[apikey] => xxx
[file] => @/absolute/path/to/file.exe;type=application/octet-stream;filename=file.exe
谢谢!
最佳答案
在 VirusTotal 自己的帮助下(荣誉,Karl)弄明白了。问题在于 PHP 5.6 如何更改 cURL。如果您使用的是 PHP 5.6,则需要添加:
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
关于php - 为什么 VirusTotal 会返回此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35568769/