Please help, I have designed a form, that contains an upload button. The form can only take file upto the size of 1mb. Every time I press the submitbutton I get:
Notice: Undefined index: myfile in F:\wamp\www\Site\CRUD\Upload\insertscript.php on line 9
Invalid file type
this is my form and below is my upload code please help.
<form action="CRUD/Upload/insertscript.php" method="post" name="signup" id="signup" onSubmit="MM_validateForm('scriptid','','R','scriptname','','R','mission','','R','programver','','R','textarea','','R');return document.MM_returnValue">
<table>
<tr>
<tr>
<td colspan="2"><label for="risks" class="vtip" title="Please Enter Comments"><font face=Arial size=2>Comments:</font></label></td>
<td colspan="2"> <textarea name="textclient" cols="25" rows="5" tabindex="4" size="50" maxlength="250" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td>
</tr>
<tr>
<td colspan="2"><label for="datecreated"><font face=Arial size=2>Upload Date:</font></label></td>
<td colspan="2"><label id="uploaddate" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"/><?php echo date('Y-m-d');?></label></td>
</tr>
<tr>
[B] <td colspan="2"><label for="browse" class="vtip" title="Please Select the File to be uploaded"><font face=Arial size=2>Attachment:</font></label></td>
<td colspan="2">
<input type="file" name="myfile" tabindex="1" />
<p><input type="hidden" name="execute" value="1" /></p>
</td> [/B]
</tr>
<tr>
<td colspan="4"><input type="submit" name="Submit" value="Submit" tabindex="8" /></td>
</tr>
</table>
</form>
this is my upload code:
$file = $_FILES['myfile'];
$allowedExtensions = array("zip", "rar");
function isAllowedExtension($fileName) {
global $allowedExtensions;
return in_array(end(explode(".", $fileName)), $allowedExtensions);
}
if($file['error'] == UPLOAD_ERR_OK) {
if(isAllowedExtension($file['name'])) {
# Do uploading here
if (file_exists("scripts/" . $_FILES["myfile"]["name"]))
{
echo $_FILES["myfile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["myfile"]["tmp_name"],
"scripts/" . $_FILES["myfile"]["name"]);
echo "Stored in: " . "scripts/" . $_FILES["myfile"]["name"];
}
} else {
echo "Invalid file type";
}
} else die("Cannot upload");
Please help :'( when i don't the input type=file make a separate form it uploads with the entire form.