I am attempting to use the virustotal API in order to upload a file to be scanned. However when I use the code from the API I receive error messages. The code being used is:
public function scanFile($filePath) {
if (!file_exists($filePath)) {
return array(
'response_code' => -4
);
}
$realPath = realpath($filePath);
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$pathInfo = pathinfo($realPath);
$fileName = $pathInfo['basename'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$parameters = array(
'file' => '@' . $realPath . ';' .
'type=' . finfo_file($finfo, $fileName) . ';' .
'filename=' . $fileName
);
} else {
// Due to a bug in some older curl versions
// we only send the file without mime type or file name.
$parameters = array(
'file' => '@' . $realPath
);
}
return $this->_doCall(VirusTotalAPIV2::URL_SCAN_FILE, $parameters);
}
And the error messages that are being returned are:
Warning: finfo_file(facebook.apk): failed to open stream: No such file or directory in C:\Users\User\Desktop\Android App Security\xampp\htdocs\androidapp\VirusTotalApiV2.php on line 48
stdClass Object ( [response_code] => 0 [verbose_msg] => Invalid submission format, the uploaded file must travel as a multipart MIME message, please review the documentation )
line 48 is this line:
'type=' . finfo_file($finfo, $fileName) . ';' .
I am really stumped and would greatly appreciate the help.
The problem is that you pass a basename for the second argument of finfo_file. That's why you have 'No such file' error, because this file is in another directory.
The solution is simply to use $realPath for finfo_file().
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.