Jump to content
Sign in to follow this  
shadowayex

Uploading Form, what do I need?

Recommended Posts

It just takes time and experience. I started in college with a good understanding of basic data structures like arrays because I had good teachers in college. Then I started working with databases, which I took a class in college about database design, but the web aspect I learned on my own, I just figured that it was time for me to learn how to use a database instead of trying to do everything with files all the time. Files are easy to use and worked for me when I was trying to learn other things (like PHP itself) where I wanted to focus on one thing and didn't want to try to learn too many things at once. Eventually I played around a little bit with regular expressions but they were pretty confusing, there's a lot there. Now I've been using these things for long enough that they don't confuse me any more, if I have a regular expression pattern that I need to create to match a certain thing I just pull up the regular expression reference (http://www.php.net/manual/en/regexp.reference.php) and start building the pattern, I use the reference to see what the specific sequences I need to use are. So it just takes time to pick these things up, the more you use them the better you'll get at it.

Share this post


Link to post
Share on other sites

Ok, it only made it to the second scan again. The problem must be when it tries to do the second preg_match. When I try doing two, it does both scans, but then the same error happens. So if the problem is in the match, it's when it tries to do the second preg_match.I set up my scale model 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(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);}

And it only gets through two. with the substr($virusscan,($v+1)) it went through them all. Does that mean that the error is in the beginning 6 letters?I learned database along side PHP, and I use databases for everything. Even with user profiles I keep the user generated styling in the database and call it out with the rest of the information and put it in the head where it needs to be. I having done much with editing files through PHP, because anything that I've needed to edit or change I just keep in a database. News entries, time trackers, user trackers, I have it all stored in databases. databases are amazing. I love working with PHP and databases. I'm not so thrilled about actually building in infrastructure of a website, layouts and design aren't my thing. But I love building PHP applications for anything I can think of. I think when I go for my Ph. D. in Computer Science I'm going to focus electives on PHP programming type classes and building database driven websites. One year of high school left, then off to college.

Share this post


Link to post
Share on other sites

Print out the $virusscan string to check what it is, what are the first several characters? It should just be string data, it shouldn't mess up preg_match. I wonder if it's an encoding issue, you can use this to print the ASCII values of the first 10 characters and compare them with an ASCII table like asciitable.com to check on it.

for ($i = 0; $i < 10; $i++)  echo $virusscan[$i] . ' (' . ord($virusscan[$i]) . ')<br>';

If I run that here with a dir command it looks fine, it starts with an ASCII space and prints the next several characters and their values.

Share this post


Link to post
Share on other sites

Results from your code:

A (65)V (86)G (71)(32)8 (56). (46)0 (48)(32)A (65)n (110)

And for a little added information, I ran this script once:

$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(\s)infections(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);}

To see what virusscan printed out to be (i printed it in the body). Then I added your script and hit refresh and it did it's breaking thing. But once I got it back up it ran the script fine. Not sure why. But this behavior is really weird and I'm not really sure where the problem could lie anymore.

Share this post


Link to post
Share on other sites

Nope. I kind of stopped working on it due to the new Firefox not displaying a couple of my pages properly, so I've been working at that. I have no solution to the problem. If you want to take another look, here is my current code:

<?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(\s+)\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);                if($matches[1][3] > 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>' . $result . '</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>

That's the entire page. I wrote a different version of it that has been applied that only allowed one upload at a time, but I would still like to get this version working, for user friendliness and whatnot.It still has the same problem, does two scans and quits. The problem seems like it's the second preg_match(), but I don't know for sure and I don't know what would be wrong with it either. It has got me stumped.

Share this post


Link to post
Share on other sites

Add some echo statements before and after preg_match to make sure that's the line it's getting stuck on. You should be able to put a series of echo statements throughout the logic (or write text to a log file) to see what line it is hanging on, or at least what the last echo statement said.

Share this post


Link to post
Share on other sites

I changed:

$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(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);

to:

fwrite($file, 'line 42, ');$virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$user}\\{$_FILES['userfile' . $i]['name']}" /trash`;fwrite($file, 'line 44, ');$result = preg_match('/Found infections(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);fwrite($file, 'line 46, ');

And got this in the file:line 42, line 44, line 46, line 42, So the code stops before the second preg_match(), but checking AVG's scan logs, it finishes the second scan. I'm not sure, but maybe the /trash part is messing it up. I just noticed function called unlink that deletes files. I'm going to mess with this and see if I can just set the virus scan to scan, and use PHP to delete infected files. I'll tell you if this fixes the problem or not.Edit: Made no difference. I'm not sure how it could complete the test, but error before the next line. I would also like to remind you that it'll run as many tests as you choose when you don't have the preg_match().

Share this post


Link to post
Share on other sites
I changed:
$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(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);

to:

fwrite($file, 'line 42, ');$virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\www\\www.hugdontmug.com\\uploads\\{$user}\\{$_FILES['userfile' . $i]['name']}" /trash`;fwrite($file, 'line 44, ');$result = preg_match('/Found infections(\s+):(\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);fwrite($file, 'line 46, ');

And got this in the file:line 42, line 44, line 46, line 42, So the code stops before the second preg_match(), but checking AVG's scan logs, it finishes the second scan. I'm not sure, but maybe the /trash part is messing it up. I just noticed function called unlink that deletes files. I'm going to mess with this and see if I can just set the virus scan to scan, and use PHP to delete infected files. I'll tell you if this fixes the problem or not.Edit: Made no difference. I'm not sure how it could complete the test, but error before the next line. I would also like to remind you that it'll run as many tests as you choose when you don't have the preg_match().

I'm just thinking might it be simpler to just make it so you can only upload one video at a time? And if you really want to do a second video upload couldn't you just make like another videoprocess-2.php, and the form itself could be made of Iframes I am guessing... so like two iframes for each upload section of the form, you could add a javascript to add more iframes or delete an iframe(and when I say add and delete I mean like just hiding it), to me you guys might be just making it harder than it has to be. If you guys want to do it your way go ahead and ignore this post, I guess...

Share this post


Link to post
Share on other sites

How about you do the virus scan before using move_uploaded_file, so you scan the temporary file before you even move it into the web folder, and only move the clean files? Then you don't have to delete it at all, since it's a temp file it will get cleaned up automatically if left in the temp folder, and you never have unscanned files available in your web folder. I doubt that has to do with anything else, just a thought.I'm not sure the problem is preg_match though. If this is what you're seeing:line 42, line 44, line 46, line 42,then it never executes the line following the scan command. So it's not that it fails on preg_match, it never makes it there (or it would print a second 44). I'm not real sure specifically what is going on, if you comment out the match and everything works then that seems to indicate a problem with preg_match, but if the execution hangs after the system call then it seems to indicate a problem with that line instead. If you can run either of them alone without problems, and there's only a problem when you run them both in a loop (have you tried running preg_match alone in a loop, even with the same data?), then something is going on between those two that I'm not aware of. It might be something like PHP using a system call to run the regex match, and getting into trouble for some reason when it has a bunch of system calls at once.You can always do all the scans first, then check the output for each one and choose whether or not to move it to the permanent folder. You can use an array for that. So you would loop through the files array once and save each filename and the results from the scan, and then loop through the new list and do the preg check and the move, if necessary.One thing I just noticed is that you're not resetting the matches array ever. You should be setting that to an empty array before each time you run preg_match.

$file_list = array();for (...){  $file = array('name' => $_FILES['userfile_' . $i]['tmp_name']);  $file['scan'] = `C:\\Progra~1\\AVG\\AVG8\\avg.....}foreach ($file_list as $file){  $matches = array();  preg_match($pattern, $file['scan'], $matches, PREG_OFFSET_CAPTURE);  // check to move}

Share this post


Link to post
Share on other sites

zachary: Thanks for your input, but iframes and whatnot aren't XHTML valid, so they're out of the question. And about uploading more than one video, the upload system is for both pictures and videos, but for some reason it won't accept videos. That's a problem I haven't quite fixed yet. But uploading more than one picture is a feature that my testers have recommended, and I think it's a great idea. I'll probably build a second form for videos and only allow one at a time, since their much bigger files and everything. Anyways, once again, thanks for your input, but due to the nature of the site and my anal retentiveness for an XHTML valid page, it won't do.

Share this post


Link to post
Share on other sites

zachary: Thanks for your input, but iframes and whatnot aren't XHTML valid, so they're out of the question. And about uploading more than one video, the upload system is for both pictures and videos, but for some reason it won't accept videos. That's a problem I haven't quite fixed yet. But uploading more than one picture is a feature that my testers have recommended, and I think it's a great idea. I'll probably build a second form for videos and only allow one at a time, since their much bigger files and everything. Anyways, once again, thanks for your input, but due to the nature of the site and my anal retentiveness for an XHTML valid page, it won't do.justsomeguy: Good call about the scanning before the file is moved. I think I remember trying the preg_match() on it's own as well, but just to make sure, I'll try again. Also, thanks for pointing out that I need to reset the array every time. I didn't think about that.I'm not to familiar with foreach() loops, so I'll look into them. But I'll rewrite the code a little bit for now and try to see if running just the preg_match() over and over works, and then see about scanning from the temp folder and then moving only clean files. That's the smarter approach that I didn't even think about :). I'll be back with the results of my work.

Share this post


Link to post
Share on other sites

Alrighty, my report:

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') {            $virusscan = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\tmp\\{$_FILES['userfile' . $i]['tmp_name']}" /trash`;            $matches = array();            $result = preg_match('/Found infections(\s+)\s+)([0-9]+)/', $virusscan, $matches, PREG_OFFSET_CAPTURE);            if($matches[3][0] > 0) {                $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' had a virus! Please clean the file and try again.<br />';            } elseif(move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $uploadfile)) {                $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 />';        }    }}

That did not. Same error.

Share this post


Link to post
Share on other sites

You're resetting $matches right after you run the match, before you check what the results are. You should reset it before the match. I see you edited that.You still might want to consider breaking it up into 2 parts though. Have one loop that loops through the upload files and only does the scan, saving the results in an array, and then have a second loop where you loop through the list of results and preg_match each result to see whether or not to move the uploaded file.

Share this post


Link to post
Share on other sites

I see, for that I'll need foreach() I'm betting, so I'll go read up on that real quick. Either that or I'm sure I could jimmy up a for statement that would do it, but I'm guess foreach would be better and I need to learn it anyways so.. yeah. I'll break it up and tell you my results.Just out of curiosity, you're thinking that the virus scan and the preg match are conflicting, aren't you? That's why you're having my split it, huh?

Share this post


Link to post
Share on other sites

I'm just wondering if those 2 are conflicting somehow. I doubt it, it doesn't really go with my experience as a programmer, but it might be worth a test.Foreach is just a shortcut for loop. These two will do the same thing:

$array = array('one', 'two', 'three', 'four', 'five');for ($i = 0; $i < count($array); $i++){  echo $array[$i];}foreach ($array as $element){  echo $element;}//bonusforeach ($array as $key => $value){  echo "the value of the element with key {$key} is {$value}";  echo $array[$key];}

Share this post


Link to post
Share on other sites

I rewrote it, and it doesn't work. I probably made a mistake somewhere and just not catching it, so here's the code:

/*----------------------------------------------------                     Upload Files----------------------------------------------------*/if($mode == 'uploading') {    $numoffiles = isset($_POST['numoffiles']) ? $_POST['numoffiles'] : 0;    $numoffiles = ($numoffiles * 1);    $file_list = array();     /*------------------------------------------------                    Scan For Viruses    ------------------------------------------------*/    for($i = 1; $i <= $numoffiles; $i++) {        if($_FILES['userfile' . $i]['type'] == 'image/jpeg' ||           $_FILES['userfile' . $i]['type'] == 'image/gif' ||           $_FILES['userfile' . $i]['type'] == 'image/png') {            $file = array('name' => $_FILES['userfile' . $i]['tmp_name']);            $file['scan'] = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\tmp\\{$_FILES['userfile' . $i]['tmp_name']}" /trash`;        } else {            $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' is not a JPEG, GIF, or PNG image.';        }    }    /*------------------------------------------------                    Move Clean Files    ------------------------------------------------*/    foreach($file_list as $file) {        $matches = array();        preg_match('/Found infections(\s+)\s+)([0-9]+)/', $file['scan'], $matches, PREG_OFFSET_CATPURE);        if($matches[3][0] = 0) {            $uploaddir = 'uploads/' . $user . '/';            $uploadfile = $uploaddir . basename(mysql_real_escape_string($_FILES['userfile' . $i]['name']));            if(move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $uploadfile)) {                $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']) . ' was not uploaded. Please try again.';            }        } else {            $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' is infected with one or more viruses. Please clean the file and try again.';        }    }}

I had to analyze a little bit to gain an understanding of what's going on (considering my little experience with arrays) but I think I basically figured it out. Looks like what's supposed to happen is I have it check for the file type. If it's a JPEG, GIF, or PNG, it builds an array that stores the name and scan results. Then the foreach() loop checks the results using the preg_match() and moves it if the number of infections is 0. Now, the one thing I don't understand is the $file_list as $file part. I thought that in a foreach() loop you put the array you want to check in the first part and the variable you want the data stored in after the as. In this case were checking an empty array and storing it in $file. Since $file is the variable holding our array with the results and whatnot in it, wouldn't that just screw up everything? Or did I misunderstand what a foreach() loop does?

Share this post


Link to post
Share on other sites

You need to build $file_list. Start it off as an empty array before the loops:$file_list = array();And add $file to it after this line:$file['scan'] = ...$file_list[] = $file;Then $file_list[0]['name'] and $file_list[0]['scan'] will be the info for the first file, $file_list[1] will be the info for the second file, etc. I saved the temp name as name, if you want to save the original name also (to rename it or whatever), you'll need to add that as well.

Share this post


Link to post
Share on other sites

Well, I was getting it all figured out, but when I tried to upload two files, still got the error >_<. Really frustrating because I was actually having a lot of fun applying the new stuff I'm learning about arrays and whatnot.

Share this post


Link to post
Share on other sites

Ok, my code looks like this now:

$scanlog = fopen('scan.txt', 'w');$movelog = fopen('move.txt', 'w');if($mode == 'uploading') {    $numoffiles = isset($_POST['numoffiles']) ? $_POST['numoffiles'] : 0;    $numoffiles = ($numoffiles * 1);    $file_list = array();     /*------------------------------------------------                    Scan For Viruses    ------------------------------------------------*/    for($i = 1; $i <= $numoffiles; $i++) {        if($_FILES['userfile' . $i]['type'] == 'image/jpeg' ||           $_FILES['userfile' . $i]['type'] == 'image/gif' ||           $_FILES['userfile' . $i]['type'] == 'image/png') {            $file = array('tmpname' => $_FILES['userfile' . $i]['tmp_name'], 'name' => $_FILES['userfile' . $i]['name']);            $file['scan'] = `C:\\Progra~1\\AVG\\AVG8\\avgscanx.exe /heur /arc /scan="C:\\wamp\\tmp\\{$_FILES['userfile' . $i]['tmp_name']}" /trash`;            $file_list[] = $file;        } else {            $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' is not a JPEG, GIF, or PNG image.';        }        $string = 'Scan' . $i . '\n';        fwrite($scanlog, $string);    }    /*------------------------------------------------                    Move Clean Files    ------------------------------------------------*/    foreach($file_list as $file) {        $matches = array();        preg_match('/Found infections(\s+)\s+)([0-9]+)/', $file['scan'], $matches, PREG_OFFSET_CATPURE);        if($matches[3][0] = 0) {            $uploaddir = 'uploads/' . $user . '/';            $uploadfile = $uploaddir . basename(mysql_real_escape_string($_FILES['userfile' . $i]['name']));            if(move_uploaded_file($_FILES['userfile' . $i]['tmp_name'], $uploadfile)) {                $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']) . ' was not uploaded. Please try again.';            }        } else {            $results .= mysql_real_escape_string($_FILES['userfile' . $i]['name']) . ' is infected with one or more viruses. Please clean the file and try again.';        }        $string = 'Move' . $i . '\n';        fwrite($movelog, $string);    }}

The results are:scanlog.txt:

Scan1\n

movelog.txt:


I realized that the \n wasn't going to work after the test btw. Anyways, It's evidently the virus scan breaking again, but it's weird because if I build a loop of just scans, it work fine. It must be when it runs something after it, it runs once then breaks (the usual error).

Share this post


Link to post
Share on other sites

Well, it doesn't really matter what else is after that code. The virus scan isn't going to break because it looks ahead in the code and sees that there's more code and decide that it's going to break, that's just not how it happens. If you remove the code after the virus scan it should perform exactly the same way, so the issue is the virus scan. If you can get it to work right in one situation and it fails in another one, what are you doing different between those?

Share this post


Link to post
Share on other sites

Well, after testing different cases, I can't figure out how I got it to run all the scans before. All my tests run up until the second one, then stop after the second one. I'm not sure if it might just be WAMP not being able to handle it, or if that even makes sense, but I just know that when it stops, I have to exit WAMP completely, wait a good 30-45 seconds, then turn it back on for it to work again. Does that help any?

Share this post


Link to post
Share on other sites

Well, you can always try to have it sleep between scans. Maybe there's an issue with loading the scanner where it's getting into trouble if it's not unloaded. Try having it sleep for a second between scans. If that works, reduce the time as much as you can. You can use sleep with seconds:sleep(1);And for microseconds use usleep. This will sleep for a tenth of a second:usleep(100000);So after it writes to the log file, put it to sleep.

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...