Here's the PHP script I'm currently using: <?php function createRandom($length) { $chars = "234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $i = 0; $random = ""; while ($i <= $length) { $random .= $chars{mt_rand(0,strlen($chars))}; $i++; } return $random; } $random = createRandom(8); $target_path = "uploads/" . $random; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "<a href='" . "/uploads/" . $random . basename( $_FILES['uploadedfile']['name']). "'>Click Here To View Your File</a>"; } else{ echo "There was an error uploading the file, please try again!<br /><a href='/problem/'>Why is this happening?</a>"; } ?> PHP: I would like to make it only capible of uploading spesific types of files.. Right now it uploads everything. I'd like it to upload: png, swf, fla, piv, stk, gif, and jpg/jpeg. Thank-you whoever can help! Jake-Johnson
probably something like this $filename= basename( $_FILES['uploadedfile']['name']); $ext= explode(".", $filename); if ($ext[1]="thefileextensionyouwant"){ ...... Code (markup):
<?php function createRandom($length) { $chars = "234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $i = 0; $random = ""; while ($i <= $length) { $random .= $chars{mt_rand(0,strlen($chars))}; $i++; } return $random; } $random = createRandom(8); $target_path = "uploads/" . $random; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $filename= basename( $_FILES['uploadedfile']['name']); $ext= explode(".", $filename); if ($ext[1]="thefileextensionyouwant"){ if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "<a href='" . "/uploads/" . $random . basename( $_FILES['uploadedfile']['name']). "'>Click Here To View Your File</a>"; } else{ echo "There was an error uploading the file, please try again!<br /><a href='/problem/'>Why is this happening?</a>"; } } ?> Code (markup):
The easy (and less secure) way to do it: $types = array('image/jpeg', 'image/gif', 'whatever/else'); if (in_array($_FILES['inputname']['type'], $types)) { // Your file handing script here } else { // Error, filetype not supported } Code (markup): The above code was taken from: sitepoint. The page goes into detail on how to make it more secure, however. As it stands, the file blah.jpg.exe would still get uploaded... This is fixable, however.