Create a php page which contains both upload form (html) and actual php code to load the file. You can have them both separately aswell.
upload.php
<?php
if(isset($_POST['submit']))
{
if ((($_FILES["file"]["type"] == "application/msword")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "<p>Specifications document uploaded succesfully <br />";
if (file_exists("uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
echo" <input type='button' value='Back to Previous Page'
onClick='javascript: history.go(-1)'> ";
}
}
}
else
{
echo "Invalid file";
}
}
else {
echo"
<form action='' method='post' enctype='multipart/form-data'>
<p><label for='file'>Filename:</label>
<input type='file' name='file' id='file' />
</p>
<p>
<input type='submit' style='margin-left:110px;' name='submit' value='Submit' />
</p>
</form>";
} ?>
Do not forget to put enctype="multipart/form-data" in the form tags. Here we are uploading word document which is of type msword so this ((($_FILES["file"]["type"] == "application/msword"))) tag specifies that, the file we are going to upload ins word type. This be changed to image type also to upload image files.
As shown in the code files goto uploads directory of your project directory. So uploads directory should be created where you have this code or you will get an error.
Thats it!! once everything is done you should be able to upload the word file.