TeroYukio Posted July 20, 2010 Share Posted July 20, 2010 I got it able to upload, however I'm trying to restrict what type of files can be uploaded. (I want just .s2z files and .honmod files to be able to be uploaded.) What should I use to restrict something like that because I tried this: if ($uploaded_type =="text/x-generic") { echo "Blah Blah Blah<br>"; $ok=0; } Which did not work. What do you suggest? <?php $target = "/*/*/public_html/upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; if ($ok==0) { echo "Sorry your file was not uploaded"; }else{ if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)){ echo "The file <b>".basename( $_FILES['uploaded']['name'])."</b> has been uploaded"; }else{ echo "Sorry, there was a problem uploading your file."; } } ?> Link to comment https://forums.phpfreaks.com/topic/208260-check-to-see-if-the-uploaded-file-is-a-valid-format/ Share on other sites More sharing options...
inversesoft123 Posted July 20, 2010 Share Posted July 20, 2010 First test with actual extension $extensionorig = end(explode('.', $filename)); if ($extensionorig == 's2z') { $ext = ".s2z"; } else if ($extensionorig == 'honmod') { $ext = ".honmod"; } else { echo "Invelid File Type. only .honmod, .s2z can be uploaded."; flag++; } Second test by reading MIME Types $mimetype = $_FILES['uploadedfile']['type']; if($mimetype != 'application/x-whatever' || $mimetype != 'application/x-whatever2' ) { $flag++; } Third test reading actual file. if ($extensionorig == 'jar') // For ex. examining a valid jar (Java) file { $f = @fopen($_FILES['uploadedfile']['tmp_name'],'r'); // open the file $s = @fread($f,2); // read first two characters. @fclose($f); if($s != "PK"){ if($flag == 0){ $error = "<RED>The file you are attempting to upload does not appear to be a valid jar (java) game file.We do not allow you to upload this game.</RED>"; } $flag++; } } Flag increment here shows error message Link to comment https://forums.phpfreaks.com/topic/208260-check-to-see-if-the-uploaded-file-is-a-valid-format/#findComment-1088455 Share on other sites More sharing options...
TeroYukio Posted July 20, 2010 Author Share Posted July 20, 2010 Thank you very much. I'll test all three of these and see which one works and I'll post back here to say if my problem was solved or not! Link to comment https://forums.phpfreaks.com/topic/208260-check-to-see-if-the-uploaded-file-is-a-valid-format/#findComment-1088669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.