Jump to content

system() call to use clamscan on PHP


mjm7867

Recommended Posts

I am using clamAV(command line antivirus) on Centos 4.4, my problem is when i use clamscan on command line it works just fine and it gives me this on the terminal as an output:
# clamscan text.txt

text.txt: OK
----------- SCAN SUMMARY -----------
Known viruses: 76734
Engine version: 0.90rc2
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.00 MB
Time: 2.096 sec (0 m 2 s)

when i run this command through php using this code:

<?php
$target_dir = "/var/www/html/webfileshare/";
$file = basename($_FILES['uploaded']['name']);
echo "<br><br>";
$target_path = $target_dir. basename($_FILES['uploaded']['name']);
$result = system("/usr/local/bin/clamscan $file");
echo $result;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path))
{
  echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";

}
else {
  echo "There was an error uploading the file, please try again!";
}
?>
And i get the following output :

----------- SCAN SUMMARY -----------
Known viruses: 76734 Engine version: 0.90rc2
Scanned directories: 0
Scanned files: 0
Infected files: 0
Data scanned: 0.00 MB
Time: 1.834 sec (0 m 1 s)
The file text.txt has been uploaded

it uploads the file, but it doesn't scans it because it says "Scanned files: 0" in the summary also in the error log  i get this message:

ERROR: Can't access file text.txt
text.txt: Permission denied

Neeed Help, thanks in advance!!

-mjm
Link to comment
https://forums.phpfreaks.com/topic/27179-system-call-to-use-clamscan-on-php/
Share on other sites

Actually it works fine without supplying $file to system:
but it scans the current directory that it is in,

cuz i m trying to upload a file and want to scan it with clamav and then upload it to the permanent folder else delete from the tmp folder,
so when i say:

system("/usr/local/bin/clamscan");
i get this :
OK /var/www/html/webfileshare/php-vir-upload.php: OK /var/www/html/webfileshare/upload_check.php: OK /var/www/html/webfileshare/php-vir-upload.php~: OK /var/www/html/webfileshare/upload.php~: OK /var/www/html/webfileshare/schema.sql: OK /var/www/html/webfileshare/upload_check.php~: OK /var/www/html/webfileshare/upload.php: OK
----------- SCAN SUMMARY -----------
Known viruses: 76734
Engine version: 0.90rc2
Scanned directories: 1
Scanned files: 8
Infected files: 0
Data scanned: 0.00 MB
Time: 2.009 sec (0 m 2 s)
The file text.txt has been uploaded

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.