Dusting off my PHP skills gentlemen. Here is a simple file upload script written in PHP in conjunction with an HTML form.
The features of the script include:
- Limit file upload size
- Limit file types for uploaded files
- Prevent file overwrites by checking if a file already exists
- Display the link once the upload is finished
Here is the HTML form:
<html>
<head></head>
<body>
<form enctype="multipart/form-data" action="up.php" method="POST">
Choose a file to upload: <input name="file_up" type="file" /><br />
<input type="submit" value="Upload!" />
</form><br />
<strong>The max file size allowed is 2MB</strong>
</body>
</html>
Here is the PHP script (this would be called "up.php" because that is what the "action" property of the HTML form is set to)
Please note that the folder (in this case "uploads/") to which files are being uploaded would have to be CHMODDED to 777

<?php
/*
This is a simple PHP Upload script written in full by Matt from RSForums.org
*/
$max_file_size = 2097152; // Set the max file size (in bytes) - DEFAULT = 2MB
$allowed_types = array('image/jpeg', 'image/gif', 'image/png'); // Set the allowed file types
/*
Here are some more common file types that you may want to include in this array:
.bmp image/bmp
.css text/css
.exe application/octet-stream
.htm text/html
.html text/html
.htmls text/html
.psd application/octet-stream
.txt text/plain
.zip application/x-compressed
.zip application/x-zip-compressed
.zip application/zip
.zip multipart/x-zip
A comprehensive list of MIME Types can be found here: http://www.webmaster-toolkit.com/mime-types.shtml
*/
$link_front = 'http://yoursite.com/uploads/'; // Set the URL down to the directory, starting with http://
$dir = '/home/www/uploads'; // Set the directory to which files will be uploaded from the home or root (WILL NOT start with http://)
//DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!!!
if (in_array($_FILES['file_up']['type'], $allowed_types)) { //Check if the file is of an allowed file type
if ($_FILES['file_up']['size'] > $max_file_size){ // Check if the file exceeds the maximum size
echo 'Your file was too large. The max size is $max_file_size bytes.';
} else{
$file = $dir . basename($_FILES['file_up']['name']);
while (file_exists($file)): // Ensure no files get overwritten & attach a random number to the front of the filename if it already exists
$_FILES['file_up']['name'] = rand(0,99) . $_FILES['file_up']['name'];
$file = $dir . basename($_FILES['file_up']['name']);
endwhile;
if (move_uploaded_file($_FILES['file_up']['tmp_name'], $file)) { // Check if sucess
echo 'Your file was uploaded! <br />';
echo 'Here is the link to your file: ';
echo $link_front . $_FILES['file_up']['name']; // Display the complete link to the uploaded file
} else {
echo "There was a problem uploading your file. Please try again later.";
}
}
} else {
echo 'You may not upload this type of file!';
}
?>
Obviously this can be modified to fit your needs. I think this is a fairly comprehensive script that demonstrates most of the features that you would want in an upload script. If nothing else, it is a good start to be built upon. Enjoy