It's too easy to upload a file into your hosted Folder.
At first we need to create a HTML page a Upload.php page and Create a Folder in the hosting place.
----------------------------------------------------------------------
index.html:
----------------------------------------------------------------------
<head>
<title>
Uploading A file
</title>
</head><body>
<table align="center" border="1">
<form enctype="multipart/form-data" action="Upload.php" method="POST">
<tr>
<td>Choose a file to upload:</td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input name="uploadedfile" type="file"/></td>
</tr>
<tr>
<td>If the File is Chosen than<br /> Click Upload Button </td>
<td align="center"><input type="submit" value="Upload File" /></td>
</tr>
</form>
</table>
</body>
----------------------------------------------------------------------
- The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded.
- The type="file" attribute of the <input> tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field.
When I click the Submit Button. Than the next script " Upload.php" Run
-------------------------------------------------------------------------
Upload.php
---------------------------------------------------
<head>
<title>
Uploading Controler
</title>
</head>
<body>
<?php
$target_path = "Folder/";
// Where the file is going to be placed
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "<h2> The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded Successfully</h2>";
}
else
{
echo "<h1>There was an error uploading the file</h1>"." <br/>"."<h1>please try again!</h1>";
}
?>
</body>
------------------------------------------
Note: Allowing users to upload files is a big security risk. Only permit trusted users to perform file uploads.
No comments:
Post a Comment