Page 1 of 1

scan files from php? can U

Posted: Mon Aug 28, 2006 2:56 am
by shyami
Hai,

Last one week onwards i am posting my question in most of the sites, and i read many books also, but i can't get anything.

here is my question


i am uploading some files through my PHP program, here i need to scan the files for virus information. I don't know how to scan the files from my coding

some sites refer clamav, i installed that but it is asking clamav database...


Is there any way to scan the files? Plz help me

Regards
Shyami

Posted: Mon Aug 28, 2006 3:06 am
by mibocote
You will have to put the file in a temporary location and then run clamav on it, having only minimal experience with clamav all I can tell you is that you should: a) look at it's documentationand b) the bin program clamscan might be the easiest.

Edit: exec() is the way to run external programs.

clamav

Posted: Mon Aug 28, 2006 5:33 am
by shyami
Thanks for u'r reply, It's very usefull to me

here is my code
----------------------
<?php
$e= "testphp.php";
echo "<br>";
$g=system("clamscan \"/$e\"");
echo "<br>";
echo "Res is : ", $g;
?>

Result is
------------


WARNING: Version mismatch (clamscan: 0.88.4, libclamav: 0.88.3) See the FAQ at http://www.clamav.net/faq.html /testphp.php: OK ----------- SCAN SUMMARY ----------- Known viruses: 60743 Engine version: 0.88.3 Scanned directories: 0 Scanned files: 1 Infected files: 0 Data scanned: 0.00 MB Time: 1.550 sec (0 m 1 s)
Res is : Time: 1.550 sec (0 m 1 s)


in $g some time is there
how i know the status of the file in my coding ?

with thanks
shyami

Posted: Fri Sep 01, 2006 3:18 pm
by han866
Hello

You can try to get the return value from clamscan. Looking at the man page, the following exit codes might be usefull...

Code: Select all

0 : No virus found.

1 : Virus(es) found.



Here is a list of available exit codes:

Code: Select all

0 : No virus found.

1 : Virus(es) found.

40: Unknown option passed.

50: Database initialization error.

52: Not supported file type.

53: Can't open directory.

54: Can't open file. (ofm)

55: Error reading file. (ofm)

56: Can't stat input file / directory.

57: Can't get absolute path name of current working directory.

58: I/O error, please check your file system.

59: Can't get information about current user from /etc/passwd.

60:  Can't  get  information  about  user  'clamav' (default name) from
       /etc/passwd.

61: Can't fork.

62: Can't initialize logger.

63: Can't create temporary files/directories (check permissions).

64: Can't write to temporary directory (please specify another one).

70: Can't allocate and clear memory (calloc).

71: Can't allocate memory (malloc).
I think all you need to do is add the $retVal to exec().

Code: Select all

<?php
$e= "testphp.php";
echo "<br>";
$g=system("clamscan \"/$e\"", $retVal);
if(!$retVal){
echo "clean";
}else{
echo $retVal;
}
?>
HTH
hanji

Posted: Mon Sep 04, 2006 12:39 pm
by AlecH
Also note though that when switching hosts, make sure they dont disable those functions because I know alot of them do.