An basic problem faced by PHP coders is how can visitor upload a file to the site.  In this tutorial we will teach you how to accept file uploads from your web site visitors.
Before you can apply PHP to manage your file uploads, let's write an HTML form that allows users to select a file to upload.

<html>
<head>
<title>Example File Upload Form</title>
</head>
<body>
Example Upload Form.<br>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select a file to upload: <input type="file" name="upload">
<input type="submit" value="Upload File">
</form>

</body>
</html>

Upload.php file
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

move_uploaded_file ($_FILES['upload'] ['tmp_name'],"upload/{$_FILES['upload'] ['name']}")

?>
</body>
</html>
and we are done

Lets know some important elements we have used in this tutorial :
enctype="multipart/form-data" : ENCTYPE determines how the form data is encoded. Whenever data is transmitted
upload.php : php file to handle upload
$_FILES['upload']['tmp_name'] : Provides temporary name of the file  created by PHP.
$_FILES['upload']['name'] = Original name of uploaded file.
move_uploaded_file() function = This function contains two parameters . first one is the temporary file name that was created by php and second is where the file to be uploaded (including the desired file name).





Comments

No Comments Yet

Page :
Your Name:
Email:
Comments: