Jump to content
Sign in to follow this  
shadowayex

Uploading Form, what do I need?

Recommended Posts

Well cmon, it's only a 2 line script. This line:$resp = `ping google.com`;Executes whatever command is in the backquotes, and saves the output in $resp. It's the exact same thing as this:$resp = shell_exec('ping google.com');You can change the ping command to "dir" if you want to see a directory listing, or you can change it to your virus scan command to do that. The echo statement just prints the results out. So if you echo the result of `"C:\Program Files\AVG\AVG8\avgscanx.exe" /heur /arc /scan="C:\wamp\www\www.hugdontmug.com\uploads\todo.txt" /clean` then you should see the output from the virus scanner.

Share this post


Link to post
Share on other sites

So that will run the command and give me the results? I can't test it right now because for some reason WAMP isn't wanting to work corretly... no idea why... I'm going to restart my computer and see if that does any good.

Share this post


Link to post
Share on other sites

File:

<?phperror_reporting(E_ALL | E_STRICT);$uploaddir = 'uploads/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);$filename = $_FILES['userfile']['name'];if($_FILES['userfile']['type'] == 'text/plain') {    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {        $Test = `"C:\Program Files\AVG\AVG8\avgscanx.exe" /heur /arc /scan="C:\wamp\www\www.hugdontmug.com\uploads\todo.txt" /clean`;/*        $test = exec($Test, $array, $report);*/        echo 'File was uploaded.';    } else {        echo 'File was not uploaded.';    }} else {    echo 'This is not a valid type.';}echo '<br />Test: ' . $Test;echo '<br />Array: ';print_r($array);echo '<br />Result: ';print_r($report);echo '<br /><a href="uploading.php">Back to Upload</a>';?>

Results:

File was uploaded.Test:Array:Notice: Undefined variable: array in C:\wamp\www\www.hugdontmug.com\upload.php on line 23Result:Notice: Undefined variable: report in C:\wamp\www\www.hugdontmug.com\upload.php on line 25

Sorry for the delay, something broke my computer and I had to fix it :). Anyways, looks like nothing to me still.

Share this post


Link to post
Share on other sites

The only way I can run a script like that and not get any output is if the command isn't understood. You probably just need to escape slashes, but you might also want to try short folder names.$Test = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\todo.txt" /clean`;

Share this post


Link to post
Share on other sites

Yay results! Now, I need to figure out how to chop up the results and get the numbers i want :). I'm being a pain, aren't I?

Share this post


Link to post
Share on other sites

Ok, so I got results with a nice test. I'm not sure how the flags and offset things work, so I just kind of copied their code and put it in and tried a simple one:

<?phperror_reporting(E_ALL | E_STRICT);$uploaddir = 'uploads/';$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);$filename = $_FILES['userfile']['name'];if($_FILES['userfile']['type'] == 'text/plain') {    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {        $Test = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\todo.txt" /clean`;        $Test2 = preg_match('/Found infections : 0/', substr($Test,3), $matches, PREG_OFFSET_CAPTURE);        echo 'File was uploaded.';    } else {        echo 'File was not uploaded.';    }} else {    echo 'This is not a valid type.';}echo '<br />Test: ';print_r($Test);echo '<br />Test2: ';print_r($Test2);echo '<br />matches: ';print_r($matches);echo '<br /><a href="uploading.php">Back to Upload</a>';?>

And here's what I got on the page:

File was uploaded.Test: AVG 8.0 Anti-Virus command line scanner Copyright © 1992 - 2008 AVG Technologies Program version 8.0.134, engine 8.0.0 Virus Database: Version 270.4.7/1544 2008-07-10 C:\wamp\www\www.hugdontmug.com\uploads\todo.txt Objects scanned : 1 Found infections : 0 Found PUPs : 0 Healed infections : 0 Healed PUPs : 0 Warnings : 0Test2: 1matches: Array ( [0] => Array ( [0] => Found infections : 0 [1] => 401 ) ) 

Right now, I'm just trying to get it to find the string. Eventually I want it to search for the Found infections line and get the number from it, then store that number in a variable. Is there a way to do that?

Share this post


Link to post
Share on other sites

Make your pattern this and see what the array of matches contains:/Found infections : ([0-9]+)/

Share this post


Link to post
Share on other sites
File was uploaded.Test: AVG 8.0 Anti-Virus command line scanner Copyright © 1992 - 2008 AVG Technologies Program version 8.0.134, engine 8.0.0 Virus Database: Version 270.4.7/1544 2008-07-10 C:\wamp\www\www.hugdontmug.com\uploads\todo.txt Objects scanned : 1 Found infections : 0 Found PUPs : 0 Healed infections : 0 Healed PUPs : 0 Warnings : 0Test2: 1matches: Array ( [0] => Array ( [0] => Found infections : 0 [1] => 401 ) [1] => Array ( [0] => 0 [1] => 426 ) ) 

Alrighty, so it still got the value, and I'm going to assume that one of the array values pulls the number found. So if that's the case, then there should be a way to call out the number. Now I'm going to take a stab at this, but mind you, I have limited experience with arrays, so this might be off bigtime:The output array looks like so:

Array(	[0] => Array		(			[0] => Found infections	:	0			[1] => 401		)	[1] => Array		(			[0] => 0			[1] => 426		))

That array is stored in matches. If I output matches[1] (which I do because I take it that the 0 in there is the value I'm trying to grab), I get this array:

Array(	[0] => 0	[1] => 426)

So.. I'm going to say if I print $mmatches[1][0] that I'll get the 0. Let's see:

echo '<br />matches[1][0]: ';print_r($matches[1][0]);

And it gives me 0. Now, all I need to know, is that 0 actually the 0 from the match? I could try it myself, but I don't happen to have a virus lying around to see :). I suppose I could try to grab the objects scanned... But I have to go for now. I'll try it when I get back and let you know my results. So far, I'm getting it (I think). And if so I'm really happy because I've been trying to make sense of arrays for ages :).Edit: I managed to whig up enough time to test it, and it gave me the number I was looking for. This is going great, but I'm going to see if I can make the number bigger than 9, just in case someone tries to upload a zip file full of crap.Edit 2: Works for numbers bigger than 9. I've got it figured out for now. If I run into any problems I'll be back though. Thanks so much for working with me. I've just got one question, but I have no time to type. I'll ask later. Thanks again.

Share this post


Link to post
Share on other sites

Alright, so about my question. I was looking at the match and I can see how it works. It looks for numbers between 1 and 9 and puts those in $matches[1][0] and whatnot. But what is the '+' for?

Share this post


Link to post
Share on other sites

Ran into a problem. When I try to use my form for videos, it doesn't work. The $_FILES array isn't even built so I can't figure out what the error is either. Does it block videos on it's own? I set max filesize in php.ini to 100M, and the largest video I've tried is only 50 MB, so that shouldn't be the problem.Edit: I ran into another problem. I built the upload page so people could upload multiple files at once. But when they try and submit, it will upload the first two fine, but 3 and on it does not. Then I have to restart WAMP a few times to get the site to load anything after that. Not sure what's causing the problem, but I can see that it does do the full script, virus scan and all, on the first two files. I don't know how far it gets with the third one, but it's before the virus scan. Here are all the related scripts:The form from media.php:

<form enctype="multipart/form-data" action="media.php?mode=uploading" method="post">    <div>        <input type="hidden" name="numoffiles" id="numoffiles" value="1" />        File 1: <input  type="file" name="userfile1" value="" /><br />        <div id="newfiles"></div>        <input type="submit" value="Send File" />        <a href="java script: void(0);" onclick="addFiles()">More Files</a>    </div></form>

The JavaScript for adding options:

var i = 1;function addFiles() {    numoffiles = prompt("How many files?","1");	if(i > 1) {	    numoffiles = (i * 1) + (numoffiles * 1); 		numoffiles = (numoffiles * 1) - 1;	}	while(i <= numoffiles) {        j = (i * 1) + 1;		document.getElementById("newfiles").innerHTML += "File " + j + ": ";		document.getElementById("newfiles").innerHTML += "<input type=\"file\" name=\"userfile" + j + "\" value=\"\" /><br />";        i = (i * 1) + 1;	}	document.getElementById("numoffiles").value = (numoffiles * 1) + 1;}

The PHP for moving the uploaded files:

if($mode == 'uploading') {    $numoffiles = isset($_POST['numoffiles']) ? $_POST['numoffiles'] : 0;    $numoffiles = ($numoffiles * 1);    for($i=1; $i<=$numoffiles; $i++) {        $uploaddir = 'uploads/';        $uploadfile = $uploaddir . basename($user . '_' . $_FILES['userfile' . $i]['name']);        if($_FILES['userfile' . $i]['type'] == 'image/jpeg' || $_FILES['userfile' . $i]['type'] == 'image/gif' || $_FILES['userfile' . $i]['type'] == 'image/png') {            if (move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $uploadfile)) {                $virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$_FILES['userfile' . $i]['name']}" /trash`;                $result = preg_match('/Found infections    :    ([0-9]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE);                if(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    :   ([10-99]+)/', substr($Test,3), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    :  ([100-999]+)/', substr($Test,3), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    : ([1000-9999]+)/', substr($Test,3), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    [10000-99999]+)/', substr($Test,3), $matches, PREG_OFFSET_CAPTURE);                }                if($matches[1][0] > 0) {                    $results .= $_FILES['userfile' . $i]['name'] . ' had a virus! Please clean the file and try again.<br />';                } else {                    $filename = $user . '_' . $_FILES['userfile' . $i]['name'];                    $filetype = $_FILES['userfile' . $i]['type'];                    $upload = mysql_query("INSERT INTO uploads (Uploader, Filename, FileType, DateUploaded, TimesViewed) VALUES ('$user','$filename','$filetype','$timestamp','0')");                    $results .= $_FILES['userfile' . $i]['name'] . ' was uploaded successfully!<br />';                }            } else {                $results .= $_FILES['userfile' . $i]['name'] . ' could not be uploaded, most likely due to file type or file size restrictions.<br />';            }        } else {            $results .= $_FILES['userfile' . $i]['name'] . ' is not a JPEG, GIF, or PNG image!<br />';        }    }}

As you can probably tell, I did some manipulation to get the loop to read each separate field, and also I have the filename set to add the user's username and an underscore before the actual name, that way file names don't conflict between users. Now I'm going to add scripts to limit the amount of files added at one time (probably 5) and check if the user is going to upload a file with the same name as one they previously uploaded and other things. But I need to get this working first. Is there something I did that could be causing the error?

Share this post


Link to post
Share on other sites

There's another option you need to change, I think it's post_max_size or something like that. Try skipping the virus scan and see if that's what is causing problems.

Share this post


Link to post
Share on other sites

Alrighty, it's the virus scan... maybe I should change it to just check all the files in the folder, so it only scans once. But then if it finds a virus that isn't the file being uploaded, it will tell the user the file was rejected anyways when it wasn't... dang it >_<. Or maybe, since it can go twice, I can scan the folder once first, before I do the file move, have it clear out any viruses it found, then scan the uploaded file afterwards...Also, I changed post_max_size to a ridiculously high number along with everything else and videos still won't upload. not sure why.

Share this post


Link to post
Share on other sites
But then if it finds a virus that isn't the file being uploaded
Umm... but why would there be a virus there in the first place? I don't think that's a problem, and you (or your host on a shared server) should run regular virus checks on everything anyway.

Share this post


Link to post
Share on other sites

I wanted to scan all files coming in, and multiple files could be coming in so if I run the scan just over the folder as the file is uploaded, another file could come in at approximately the same time and then the scan on the none infected file's side would pick up the virus in the other file and reject the clean file... crazy scenario I know. I do run scans everyday at 9. I'm just trying to make sure that some user doesn't decide to upload a whole bunch of viruses between my virus scans and ultimately kill the server before the server has a chance to defend itself. It's AVG so what it'll do is if it does find an infection between scans it'll ask me what to do. That won't do me much good if I'm at Anime Club or running errands for my mother now will it?I guess I could just set it up so after every upload, AVG scans and gets rid of infected files and just post a warning up saying that if any files disappear it's because they were infected and hope that a virus doesn't infect the whole directory and a lot of users lose their stuff. I liked my idea of scanning each file right as it came in >_<.Edit: Well, I set it up to work like my last paragraph. I set it up so that it alerts the user when they come to their media managing page that files have been moved or deleted, some possibilities why, and a link to send me a message if they have any questions. I think it'll do.

Share this post


Link to post
Share on other sites

Maybe you should just figure out why the virus scan is the problem and fix it. If you just put several large movies there and manually scan them with the command line how long does it take? Does the server ever become unstable? You you considered using another AV (ClamAV, for example)?

Share this post


Link to post
Share on other sites

Well, I'll explain exactly what happens. The first file goes through, AVG pops up in the corner and scans the file. Everything runs fine. The second file goes the same way. When the third file goes, however, the virus scan never pops up. The page says it's loading, and does so until you try to do anything else. At that exact moment no one can connect to the site anymore. And to solve it I have to go through an annoying process.I first have to try to put WAMP offline. It says something about the action can't be done or something. Then I have to right click and click exit. Then I bring it back up and it's offline. I try to put it online and the same error pops up. I right click and exit again. Then I load it up one more time and it loads and is online. Not sure why any of it happens, and it doesn't seem to be a problem on AVG's side because everything else runs fine. Nothing else stops, besides Firefox occasionally. But not every time so I don't know what's up with that. It sounds like WAMP is having a problem. At some point in time I'm going to learn how to install Apache, PHP, MySQL, and phpMyAdmin on my own, securely. But until then I need WAMP to do everything for me.

Share this post


Link to post
Share on other sites

Try to figure out what is going on. Apache should have some logs that you can check for details to see if Apache is picking up an error, or you can also try the Windows event logs in the admin tools section in the control panel. If AVG has its own logs check there as well. Try to find some log entries that may at least explain which component is crashing.

Share this post


Link to post
Share on other sites

I checked all the logs. The AVG event log shows the start scan and scan results events for the first two, but not even a start on the third one. No other log (including the admin tools one) has anything, until I go through the process of shutting it down and restarting it, in which case they tell me about both the failed and succeeded attempts in putting it offline and back online. So overall, there's nothing to tell be where the error comes in.I built a test page and had it perform this:for($i=1;$i<=5;$i++) { $virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$user}\\todo.txt" /trash`;}And it worked every time. 5 tests were performed and completed.I added this: $result = preg_match('/Found infections : ([0-9]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE); if(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([10-99]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([100-999]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([1000-9999]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections :)[10000-99999]+)/', substr($virusscan,3), $matches, PREG_OFFSET_CAPTURE); }And it errored. So I looked through that, and I saw that three in there. Now, I honestly don't know what the three is for, but it seemed magic number 3 was appear, so I changed it to 4. Three tests fired before the error. So theory is, that number -1 is the highest amount of tests that can be fired. So since my loop goes until $i = $numoffiles, I changed my test thing to look like this:$v = 5;for($i = 1;$i <= $v;$i++) { $virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$user}\\todo.txt" /trash`; $result = preg_match('/Found infections : ([0-9]+)/', substr($virusscan,($v + 1)), $matches, PREG_OFFSET_CAPTURE); if(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([10-99]+)/', substr($virusscan,4), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([100-999]+)/', substr($virusscan,4), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections : ([1000-9999]+)/', substr($virusscan,4), $matches, PREG_OFFSET_CAPTURE); } elseif(!isset($matches[1][0])) { $result = preg_match('/Found infections :)[10000-99999]+)/', substr($virusscan,4), $matches, PREG_OFFSET_CAPTURE); }}And it ran all 5 tests. So I applied that idea to the uploading page in question. The file in question now looks like this:media1.php

<?phpinclude('PHP_Files/connect.php');include('PHP_Files/globals.php');$results = '';/*----------------------------------------------------                     Upload Files----------------------------------------------------*/if($mode == 'uploading') {    $numoffiles = isset($_POST['numoffiles']) ? $_POST['numoffiles'] : 0;    $numoffiles = ($numoffiles * 1);    for($i=1; $i<=$numoffiles; $i++) {        $uploaddir = 'uploads/' . $user . '/';        $uploadfile = $uploaddir . basename(mysql_real_escape_string($_FILES['userfile' . $i]['name']));        if($_FILES['userfile' . $i]['type'] == 'image/jpeg' || $_FILES['userfile' . $i]['type'] == 'image/gif' || $_FILES['userfile' . $i]['type'] == 'image/png') {            if(move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $uploadfile)) {                $virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$user}\\{$_FILES['userfile' . $i]['name']}" /trash`;                $result = preg_match('/Found infections    :    ([0-9]+)/', substr($virusscan,($numoffiles+1)), $matches, PREG_OFFSET_CAPTURE);                if(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    :   ([10-99]+)/', substr($virusscan,($numoffiles+1)), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    :  ([100-999]+)/', substr($virusscan,($numoffiles+1)), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    : ([1000-9999]+)/', substr($virusscan,($numoffiles+1)), $matches, PREG_OFFSET_CAPTURE);                } elseif(!isset($matches[1][0])) {                    $result = preg_match('/Found infections    [10000-99999]+)/', substr($virusscan,($numoffiles+1)), $matches, PREG_OFFSET_CAPTURE);                }                if($matches[1][0] > 0) {                    $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' had a virus! Please clean the file and try again.<br />';                } else {                    $filename = mysql_real_escape_string($_FILES['userfile' . $i]['name']);                    $filetype = mysql_real_escape_string($_FILES['userfile' . $i]['type']);                    $upload = mysql_query("INSERT INTO uploads (Uploader, Filename, FileType, DateUploaded, TimesViewed) VALUES ('$user','$filename','$filetype','$timestamp','0')");                    $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' was uploaded successfully!<br />';                }            } else {                $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' could not be uploaded, most likely due to file type or file size restrictions.<br />';            }        } else {            $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' is not a JPEG, GIF, or PNG image!<br />';        }        $results .= '<br />The number in numoffiles is ' . $numoffiles;    }}$title = 'Media - ' . $user;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title><?php echo $title ?></title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><script src="JS_Files/mmenu.js" type="text/javascript"></script><script src="JS_Files/menuItems.js.php" type="text/javascript"></script><script src="JS_Files/functions.js" type="text/javascript"></script><script src="JS_Files/online.js" type="text/javascript"></script><script type="text/javascript">window.onload = function() {    setInterval("online()", 1000);}</script></head><body><div class="ads"><h1>Ads here</h1></div><div class="content"><div class="banner"></div><p class="userinfo"><?php echo 'Hello ' . $user . '! ' . $alert; ?></p><div style="padding: 10px;"><?phpif($_SESSION['logged_in'] != true) {echo <<< EOT<form action="login.php" method="post">    <div>        <p>Username: <input type="text" name="username" value="" /></p>        <p>Password: <input type="password" name="password" value="" /></p>        <input type="submit" name="submit" value="Log In" />    </div></form>EOT;}else {    echo '<p>' . $results . '</p>';    echo <<< EOT<a href="media1.php">Check My Media</a> |<a href="media1.php?mode=uploadfiles">Upload Files</a>EOT;    if($mode == '') {        echo <<< EOT<p>In this section you can look over and edit your media.</p><h3>Pics</h3><h3>Videos</h3>EOT;    } elseif($mode == 'uploadfiles') {        echo <<< EOT<form enctype="multipart/form-data" action="media1.php?mode=uploading" method="post">    <div>        <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />        <input type="hidden" name="numoffiles" id="numoffiles" value="1" />        File 1: <input type="file" name="userfile1" value="" /><br />        <div id="newfiles"></div>        <input type="submit" value="Send File" />        <a href="java script: void(0);" onclick="addFiles()">More Files</a>    </div></form>EOT;    }}mysql_close($link);?></div></div></body></html>

And it made it through three out of 4 tests. So I change it to +2 and tried 5 uploaded, and it only made it through two. What is that number for and why is it behaving this way? Is there a way to make it work all the time?

Share this post


Link to post
Share on other sites

By now you should know how to look that stuff up, check the manual for substr:http://www.php.net/manual/en/function.substr.phpThe second argument to substr is the position to start at. I'm not even sure why you're using substr, when you test inside substr($virusscan, 3) you're testing everything inside the $virusscan string except the first 3 characters. I'm not sure what the point of that is. I'm not sure what you're doing with the regular expressions either, this is the only one you need:$result = preg_match('/Found infections : ([0-9]+)/', substr($virusscan,($v + 1)), $matches, PREG_OFFSET_CAPTURE);The pattern ([0-9]+) matches any string of numbers. It matches "0", it matches "100", it matches "999", it matches "1922839928284701029203209357192845", it matches any string of one or more digits. I'm not even sure what something like ([10000-99999]+) would tell the regex engine to do, when you put characters in brackets it is a range. [a-z] matches any lowercase letter. [A-Z] matches any uppercase letter. [a-zA-Z] matches any letter. [a-zA-Z0-9] matches any letter or number. I'm not sure what [10000-99999] matches, it might just match numbers between 10000 and 99999. But so will [0-9]+. But if the virus scan part is working, and it has a problem with the regular expression matching, I would look there for the problem.

Share this post


Link to post
Share on other sites

Ok, to explain that, the results come back from the command prompt in a certain format. Everytime the number gets one digit higher, it actually removes a space in front of it, throwing off the actually string being matched.for example:

Found infections    :    1   //meaning one infection was foundFound infections    :   56   //56 infections were foundFound infections    :  734   //734 infectsion were found

The number of space between the colon and the number decreases with each new digit. I wrote them all to cover that whole range, as a precaution in case someone wanted to upload a while bunch of viruses (I'm a security freak).Anyways, now I see what 0-9 does so I can just take a space off from each and leave 0-9 there. And the only reason the substr was there was because it was in the example and I didn't understand what it did (I probably should have looked it up ahead of time :)). But I'll toy with the stuff some more now that I better understand what everything means.

Share this post


Link to post
Share on other sites

There's another way to match whitespace. So you can look for "Found infections", then one or more spaces, then a colon, then one or more spaces, then one or more digits. That's the power of regular expressions. \s matches a whitespace character (space, newline, tab, etc), so this pattern should work:$result = preg_match('/Found infections(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);The matches array will be different though, $matches contains one element for each item in parentheses, so it will include the strings that match the whitespace also. The digits will be the third match instead of the first one.

Share this post


Link to post
Share on other sites

Alrighty, I'll put that in and change the array as needed then test it out again. Once again, thanks for working with me. I'm very ignorant at times. There's a lot I don't know as my resources are limited.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...