[code]<?PHP //If the submit button is pressed: if($_POST['submit']){ //category you would like to upload files to $directory = "/httpdocs/0406meetphotos/"; //max file size $max_file_size = "20480000"; //allowed files types users can upload $allowedfile[] = "image/gif"; //.gif $allowedfile[] = "image/jpeg"; //.jpeg $allowedfile[] = "image/jpg"; //.jpg $allowedfile[] = "video/x-ms-wmv"; //.wmv $allowedfile[] = "video/x-msvideo"; //.avi $allowedfile[] = "video/mpeg"; //.mpeg //Check max file size if (is_uploaded_file($_FILES["file"]["tmp_name"])) { if($_FILES["file"]["size"]>$max_file_size) { $is_uploaded = "failed"; echo 'Sorry, this file is too large. The maximum filesize is '.$max_file_size.' bytes, although your file is '.$_FILES["file"]["size"].'. '; exit(); //If $is_upload = failed, then we stop the uploading process } //Check file type if(!in_array($_FILES["file"]["type"],$allowedfile)) { $is_uploaded = "failed"; echo 'Sorry, wrong file type, "'.$_FILES["file"]["type"].'" is not allowed. '; exit(); //If $is_upload = failed, then we stop the uploading process } //Check to see if file exists | If it does, then we stop the process, although if it doesnt then we continue if(file_exists($directory.$_FILES["file"]["name"])) { $is_uploaded = "failed"; echo 'Sorry, this file already exists. '; exit(); //If $is_upload = failed, then we stop the uploading process } //Now, if $is_uploaded does NOT = failed, we remove invalid characters in the filename, and replace all spaces with underscores if($is_uploaded!="failed") { $replace = array("$","%","#","@","!","&","^","*","(",")","-"); $new = str_replace($replace,"",$_FILES["file"]["name"]); $fileName = str_replace(" " , "_" , $new); //If the directory defined in the beggining does not exist, we create it and CHMOD it to 777 if(! is_dir($directory)){ mkdir($directory,0777); } //upload the file and check for errors if (move_uploaded_file($_FILES["file"]["tmp_name"], $directory.$fileName)) { echo "Your file, ". $fileName ." has successfully been uploaded! Click <a href=\"".$directory.$fileName."\">Here</a> to view your file."; } else { echo 'Sorry, your file has not uploaded.'; exit(); } } } else { echo 'There has been an unknown error while uploading'; exit(); } } ?> [/code] [code]<table width='90%' cellpadding='0' cellspacing='0' style='border:1px solid #000000;'> <tr> <td colspan="2" style='border-bottom:1px solid #000000;padding:3px;padding-left:6px;'>Upload File</td> </tr> <tr> <td> <center> <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> <table> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Choose File:</font></td> <td><input type="file" name="file"> <input name="submit2" type="submit" value="Upload File"></td> <input type="hidden" name="submit" value="true"> </tr> </table> </form> </center>[/code]