<pre>
<?php
if(isset($_FILES['myfile']) && isset($_POST['pattern'])) {
$uploaddir = '/var/www/PhpTraining/uploads';
$fileName = $_FILES['myfile']['name'];
$test = move_uploaded_file($_FILES['myfile']['tmp_name'], "$uploaddir/$fileName");
if($test) { echo "Success Uploads"; } else { echo "Not Uploaded"; }
$content = ' ';
$pattern = ' ';
$pattern = $_POST['pattern'];
foreach(file("$uploaddir/$fileName") as $line) {
if(preg_match("/$pattern/i",$line)) {
$content.=$line;
}
}
}
?>
</pre>
<html>
<head><center><h2>Assignment 1: Search Pattern in Uploaded File</h2></center></head>
<body bgcolor='lightgreen'>
<form enctype="multipart/form-data" method='post'>
<label>Enter pattern to Search: </label>
<input type='text' name='pattern' value='<?php echo $pattern;?>'/><br /><br>
<label>Choose File:</label> <input type='file' name='myfile' /> <br><br>
<input type='submit' value='upload and Search' />
</form>
<textarea rows='10' cols='60' readonly="readonly"><?php echo $content; ?></textarea>
</body>
</html>
No comments:
Post a Comment