How about this:
PHP Code:
<?php
$types = array("image/png","text/html","text/js","text/css");
if(isset($_POST['submit'])){
$error = true;
foreach($types as $type){
if($_FILES['uploadedfile']['type'] == $type){
$error = false;
}
}
if(!$error){
$target_path = "uploads/";
$target_path = $target_path . rand(0, getrandmax()) . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "Your file has been uploaded to <a href='".$target_path."'>".$target_path."</a> The code to upload it to the forum is: <br /><input type='text' readOnly='true' onclick='this.select();' value='[url=http://mysite.com/".$target_path."]".$target_path."[/url]' />";
} else{
echo "There was an error uploading the file, please try again!";
}
} else if($_FILES['uploadedfile']['name'] != ""){
echo "Looks like you have a ".$_FILES["uploadedfile"]["type"]." type! You can't!";
} else {
echo "No file";
}
} else { echo "No data!"; }
?>
Bookmarks