Click to See Complete Forum and Search --> : Scan the uploaded file
bee_kishore
08-30-2005, 01:10 AM
Hi All!,
I developed an application using PHP called 'Resume Manager' where user can register and upload their resume. But i want to scan the uploaded file (in this case resume) before moving the file on to the server.
Can anyone helps me regarding this.
Thanx in advance,
WIth regards,
Kishore
bokeh
08-30-2005, 03:02 AM
Scan it for what? You could analyse it to assess if it is of the correct mime type or content. What type of file will it be and what will it contain?
charlesdavison
08-31-2005, 07:07 AM
I'm also quite curious on this; bee_kishore - how do you scan a file to make sure it is of the correct type? For example, to make sure an MP3 is in fact an MP3?
And how would you scan for viruses in PHP?
bee_kishore
09-05-2005, 12:13 AM
Hi friends!
As i said earlier, i want to scan the uploaded file (in my cases, resumes/cv in word or text format posted by applicants) before moving it on to my server to protect it from virus treat. Can any one help me regarding this.
WIth regards,
-KISHORE
bokeh
09-05-2005, 04:02 AM
<?php
// set variables
$field_name = 'upload'; //This is the field name in your form. e.g. <input type="file" name="upload">
$upload_tmp = $_FILES[$field_name]['tmp_name'];
$upload_type = $_FILES[$field_name]['type'];
// test file
if(accepted_type($upload_tmp, $upload_type)){
// uploaded file is a text or MS word doc file
}else{
// uploaded file is NOT a text or MS word doc file
}
function accepted_type($upload_tmp, $upload_type, &$error = NULL)
{
function is_ASCII($data)
{
$bad = false;
for($x = 0, $y = strlen($data); !$bad && $x < $y; $x++)
{
$bad = (ord($data{$x}) > 127);
}
return !$bad;
}
if(!is_uploaded_file($upload_tmp)) {
if(!is_null($error))$error = 'Cannot modify a file you did not upload!';
return FALSE;
}
if(!(is_readable($upload_tmp) and $data = file_get_contents($upload_tmp))){
if(!is_null($error))$error = 'Cannot open file to run checks!';
return FALSE;
}
print $upload_type;
if($upload_type != ('application/msword' || 'text/plain')){
if(!is_null($error))$error = 'File is not an accepted type!';
return FALSE;
}
if($upload_type == 'application/msword'){
if(eregi('0M8R4KGxGuE=', base64_encode(substr($data, 0, 8)))) return TRUE;
if(!is_null($error))$error = 'Mime type ('.$upload_type.')does not match file content!';
return FALSE;
}
if($upload_type == 'plain/text'){
if(is_ASCII($data)) return TRUE;
if(!is_null($error))$error = 'Mime type ('.$upload_type.')does not match file content!';
return FALSE;
}
if(!is_null($error))$error = 'Error: type not specified';
return FALSE;
}
?>
ShrineDesigns
09-05-2005, 02:23 PM
most anti-virus programs have a command-line interface, so you can simply do something like this, and depending on what is returned (would require some testing) you should be able to determine what is a threat<?php
$av = 'path/to/anti-virus program';
$f = $_FILES['upload']['tmp_name'];
passthru("$av -scan $f", $retval); // you will need to know what parameters to set
echo $retval;
?>
skydiver700
10-06-2005, 05:27 PM
Hi All!,
I developed an application using PHP called 'Resume Manager' where user can register and upload their resume. But i want to scan the uploaded file (in this case resume) before moving the file on to the server.
Can anyone helps me regarding this.
Thanx in advance,
WIth regards,
Kishore
I want to know the code of how to scan uploaded file in ASP.NET,thx
skydiver700
10-06-2005, 05:30 PM
Plz Any one Know the code of how to scan uploaded file In ASP.Net plz send it
chazzy
10-06-2005, 08:06 PM
Plz Any one Know the code of how to scan uploaded file In ASP.Net plz send it
I would seriously consider posting in the ASP forum.