Here is my uploader that works for image files:
><?php
if (is_uploaded_file($_FILES['userpic']['tmp_name'])) {
if ((substr($_FILES['userpic']['name'], -4) == '.jpg') || (substr($_FILES['userpic']['name'], -4) == '.gif') || (substr($_FILES['userpic']['name'], -4) == '.png')) {
if ($_FILES['userpic']['size'] > 300000) {
exit("Picture is too large! Try compressing more!");
}
if (strlen($_FILES['userpic']['type']) > 26) {
exit("Please rename the picture to something with a shorter name and try again!");
}
$filename = $_FILES['userpic']['name'];
if (file_exists($_FILES['userpic']['name'])) {
exit("This file already exists, please rename it!");
}
copy($_FILES['userpic']['tmp_name'], "/home/sector-/public_html/pics/".$_FILES['userpic']['name']);
echo "File has been uploaded to S19's server. Here are your details:<p>";
echo "The URL to your picture is:<b> <a href=\"http://pics.sector-19.com/".$_FILES['userpic']['name']."\">http://pics.sector-19.com/".$filename."</a></b><br>";
echo "The code to put this on the forums is:<b> [img=http://pics.sector-19.com/".$_FILES['userpic']['name']."]</b>";
}
else { exit("This is not a valid image file"); }
} else {
echo "Possible file upload attack. Filename: " . $_FILES['userpic']['name'];
}
?>