Want to make a simple PHP file uploader for your site?
Here it is!
Code:
<?php
$action = $_POST["action"];
$max_size = "10485760"; // Max size in BYTES (Currently 10MB)
echo "
<html>
<center>
<form action='upload.php' method=post enctype='multipart/form-data'>
Select A File To Upload:
<input type='file' name='filename'>
<input type='reset' value='Reset'>
<input type='hidden' name='action' value='upload'>
<input type='submit' value='Upload File'>
</form>";
if ($action == 'upload')
{
if ($_FILES["filename"]["size"] > $max_size) die ("File too big! Try again...");
copy($_FILES["filename"]["tmp_name"],"./".$_FILES["filename"]["name"]) or die("<font color='red'>Unknown error! Please e-mail me if the problem persists.</font>");
echo "<font color='green'>File Uploaded. Click here to see your file(s).</font>"; // for debug --> $filename --> ".$destination."/".$filename_name."</h2>";
}
?> The variables at the beginning set the Action to post the picture into the supplied folder
uploads.
Hence we need to create a folder in the main directory with
CHMOD 777 [all permissions] to enable the files to be uploaded.
The form is basic input fields.
Files that are larger than the allocated amount will not be uploaded.