On Fri, 2002-02-01 at 14:02, toni baker wrote: > I would like to prevent users from uploading a file > that contains more than 4 pipes or less than 2 pipes. > The code below prevents users from uploading a file > containing more than 4 pipes, but not less than 2 > pipes. Should I use awk, ereg, or sed? Thanks
Unless you *have* to spawn processes to do this for you for some reason, you can keep things a lot simpler by doing it in PHP, something like this: <?php error_reporting(E_ALL); function check_file($filename) { if (!$upload_file = file($filename)) { return false; } while (list(, $line) = each($upload_file)) { $num_pipes = substr_count($line, '|'); if ($num_pipes < 2 || $num_pipes > 4) { return false; } } return true; } $userfile = 'testpipes.txt'; if (check_file($userfile)) { echo "File passed.\n"; } else { echo "File failed.\n"; } ?> Hope this helps, Torben > system ("/bin/cat $userfile|/bin/sed -n > 's/.*|.*|.*|.*|.*|/&/p'> pipes.txt; > $fd =fopen("pipes.txt", 'r'); > $pipes5=fgets($fd,50); > echo ($pipes5); > fclose($fd); > > if ($pipes5) { > print "wrong number of pipes"; > } > > The uploaded file below should not pass but it does: > > aaaaa|bbbbb|ccccc|ddddd|eeeee > aaaaa|bbbbb|ccccc| > aaaaa|bbbbb|ccccc|ddddd > aaaaa|bbbbb > aaaaa|bbbbb|ccccc|ddddd|eeeee -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]