
Here is a basic PHP upload form, it can be used to upload any file, from an images to a PDF or zip file, the code is easy to understand and implement.
<html>
<head>
<title>File Uploader</title>
</head>
<body>
<h3>Upload your file</h3>
Select a file to upload:<br>
<form action=”uploader.php” method=”post” enctype=”multipart/form-data”>
<input type=”file” name=”file” size=”45″>
<br>
<input type=”submit” value=”Upload File”>
</form>
</body>
</html>
The enctype attribute specifies which content-type to use when the form is submitted. “multipart/form-data” is used when a form requires binary data, like the contents of the file to be uploaded.
<?php
if( $_FILES['file']['name'] != “” )
{
copy ( $_FILES['file']['tmp_name'],
/*The directory underneath should point to where you want your files uploaded*/
“C:/Apache/htdocs/” . $_FILES['file']['name'] )
or die( “Could not copy file” );
}
else
{
die( “No file specified” );
}
?>
<html>
<head>
<title>Upload complete</title>
</head>
<body>
<h3>File Uploaded</h3>
<ul>
<li>Sent: <?php echo $_FILES['file']['name']; ?></li>
<li>Size: <?php echo $_FILES['file']['size']; ?> bytes</li>
<li>Type: <?php echo $_FILES['file']['type']; ?></li>
</ul>
<a href=”<?php echo $_FILES['file']['name']; ?>”>Click here to view file</a>
</body>
</html>
The type=”file” specifies that the input should be processed as a file. This is a very simple way of uploading files. For security reasons, you should add restrictions on what the user is allowed to upload and who can use the upload form.




