Search This Blog
Monday, September 20, 2010
Multiple File Upload & Data Submission with File Validation
code to paste:
submit.php
<html>
<body><br>
<table border="0" cellpadding="2" cellspacing="2" align="center" bgcolor="#cccccc">
<form action="upload.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="3" align="center"><font face="verdana" size="2"><b>Data & File Submission</b></font></td>
</tr>
<tr>
<td align="right"><font face="verdana" size="2">Complete Name:</font></td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td align="right"><font face="verdana" size="2">Upload filename .tx, .doc extension:</font></td>
<td><input type="file" name="file1" id="file" /> </td>
</tr>
<tr>
<td align="right"><font face="verdana" size="2">Upload filename .jpg, .gid extension:</font></td>
<td><input type="file" name="file2" id="file" /></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</form>
</table>
</body>
</html>
upload.php
<?php
$name=$_REQUEST['name'];
$filename=($_FILES['file1']['name']);
$filename2=($_FILES['file2']['name']);
echo $name;
echo "<br>";
echo $filename;
echo "<br>";
echo $filename2;
$ext1 = strrchr($filename, ".");
$ext2 = strrchr($filename2, ".");
echo "<br>";
echo $ext1;
echo "<br>";
echo $ext2;
if (($ext1==".txt" || $ext2==".doc") && ($ext2==".jpg" || $ext2==".gif"))
{
$target = "upload/";
$targetx = $target . basename( $_FILES['file1']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['file1']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else
{
//Gives and error if its not
}
$targetx = $target . basename( $_FILES['file2']['name']);
//Writes the photo to the server
if(move_uploaded_file($_FILES['file2']['tmp_name'], $targetx))
{
//Tells you if its all ok
}
else
{
//Gives and error if its not
}
echo "<br>";
echo "<br>";
echo "<br>";
echo "<p align='center'><font face='verdana'>data & file submission success!</font></p>";
}
else
{
echo "<p align='center'><font face='verdana'>Input a valid required file, go back to previous page!</font></p>";
}
?>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment