pleek Posted December 7, 2008 Share Posted December 7, 2008 ok quick question, does anybody know what a rom that is .nes would be as an upload type? i tried application/nes but that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/ Share on other sites More sharing options...
.josh Posted December 7, 2008 Share Posted December 7, 2008 http://www.google.com/search?hl=en&q=nes+rom+mime+type&btnG=Google+Search Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708769 Share on other sites More sharing options...
ratcateme Posted December 7, 2008 Share Posted December 7, 2008 maybe application/octet-stream? try uploading a file and print_r($_FILES) to see what it comes out as. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708770 Share on other sites More sharing options...
pleek Posted December 7, 2008 Author Share Posted December 7, 2008 so according to the first reply the correct $uploaded_type is "application/x-snes-rom" correct? so for a NES it would be "application/x-nes-rom" right? Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708774 Share on other sites More sharing options...
.josh Posted December 7, 2008 Share Posted December 7, 2008 only one way to find out... Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708778 Share on other sites More sharing options...
pleek Posted December 7, 2008 Author Share Posted December 7, 2008 ok, i think that means try it. lol, i did and it didn't work. here's my upload script. <?php $target = "Games/"; $target = $target . basename( $_FILES['uploaded']['name']) ; //This is our limit file type condition if ($uploaded_type != "application/x-nes-rom") { echo "Only .NES files are allowed.<br>"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> now what.... Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708782 Share on other sites More sharing options...
.josh Posted December 7, 2008 Share Posted December 7, 2008 Maybe it doesn't work because $uploaded_type doesn't seem to exist (as in, you didn't assign anything to it) $_FILES Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708788 Share on other sites More sharing options...
ratcateme Posted December 7, 2008 Share Posted December 7, 2008 make an upload form that submits to <?php echo "<pre>"; print_r($_FILES); ?> and upload some files to it and see what they come up as. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708799 Share on other sites More sharing options...
pleek Posted December 7, 2008 Author Share Posted December 7, 2008 make an upload form that submits to <?php echo "<pre>"; print_r($_FILES); ?> and upload some files to it and see what they come up as. Scott. thank you for that, and your first post correctly told me the type Array ( [uploadedfile] => Array ( [name] => 3DWORLD.NES [type] => application/octet-stream [tmp_name] => /tmp/phpyQzpdv [error] => 0 [size] => 262160 ) ) so i changed my code to <?php $target = "Games/"; $target = $target . basename( $_FILES['uploaded']['name']) ; //This is our limit file type condition if ($_FILES['userfile']['type'] != "application/octet-stream") { echo "Only .NES files are allowed.<br>"; echo "<pre>"; print_r($_FILES); } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> but it still doesn't work. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708810 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 Why not use the extension? //This is our limit file type condition if (!preg_match("/.*\.nes$/i", $type)) { echo "Only .NES files are allowed.<br>"; echo "<pre>"; print_r($_FILES); } Why not just check the filename? Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708812 Share on other sites More sharing options...
pleek Posted December 7, 2008 Author Share Posted December 7, 2008 i tried the code you posted and i get the same results Only .NES files are allowed. Array ( [uploadedfile] => Array ( [name] => 3DWORLD.NES [type] => application/octet-stream [tmp_name] => /tmp/php7s7TE1 [error] => 0 [size] => 262160 ) ) and as for "Why not just check the filename?" that would be fine as long as i can check the file name and extension. so like "if file = game.nes" Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708814 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 i tried the code you posted and i get the same results and as for "Why not just check the filename?" that would be fine as long as i can check the file name and extension. so like "if file = game.nes" Does the filename have to br a specific game? I am confused. The code I posted above will verify that the extension is .nes no matter the case. Is that not what you wanted? As far as verifying that the file is a true .nes and not just some text file I uploaded, you can check that octet stream, but yea. I am not sure how you would go about verifying that. EDIT: I noticed I used $type, instead of the $_FILES['userfile']['name'] use that instead of $type, sorry I had it set to $type for testing purposes. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708824 Share on other sites More sharing options...
.josh Posted December 7, 2008 Share Posted December 7, 2008 Once again, try using the correct variable name in your condition. You're checking $_FILES['userfile']['type] and that doesn't exist. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708826 Share on other sites More sharing options...
pleek Posted December 7, 2008 Author Share Posted December 7, 2008 i tried the code you posted and i get the same results and as for "Why not just check the filename?" that would be fine as long as i can check the file name and extension. so like "if file = game.nes" Does the filename have to br a specific game? I am confused. The code I posted above will verify that the extension is .nes no matter the case. Is that not what you wanted? As far as verifying that the file is a true .nes and not just some text file I uploaded, you can check that octet stream, but yea. I am not sure how you would go about verifying that. To that, no the the filename does not have to be a specific game. I added your code to my script and it didn't work. Current code... <?php $target = "Games/"; $target = $target . basename( $_FILES['uploaded']['name']) ; //This is our limit file type condition if (!preg_match("/.*\.nes$/i", $type)) { echo "Only .NES files are allowed.<br>"; echo "<pre>"; print_r($_FILES); } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> Once again, try using the correct variable name in your condition. You're checking $_FILES['userfile']['type] and that doesn't exist. Um. ok then what should i check? I was going by what was posted earlier about $_file that linked me to http://us3.php.net/features.file-upload Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708828 Share on other sites More sharing options...
.josh Posted December 7, 2008 Share Posted December 7, 2008 In your code, I see you using 3 different names in different places: $_FILES['uploaded'].. $_FILES['userfile'].. $_FILES['uploadedfile'].. Well what did you name your file input field in your form? It's really simple: If you have a form with a file upload input field and you name it "blah" then you use "blah" not "someothername". Posted examples are just that: examples. You need to put your own var names into it. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-708846 Share on other sites More sharing options...
pleek Posted December 8, 2008 Author Share Posted December 8, 2008 so can you give me a working example? Im having a problem following what you guys are telling me. I understand what your telling me and how its supposed to work. But i can't figure out the code. thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-709870 Share on other sites More sharing options...
.josh Posted December 8, 2008 Share Posted December 8, 2008 There's a working example in the manual. Link has already been provided in this thread. Are you seriously wanting me to type out for you how to use a variable name to refer to its value? $name = "something"; echo $came; // why won't this work? echo $blah; // omg it still won't print 'something' echo $wtf; // wtf is going on, for the love of god, please just echo 'something' echo $mame; // ooh, ooh, I'm getting closer, I can feel it.... echo $name; // oh...there it is. I guess I had to spell it like 'name' cuz like, that's the variable's name Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-709993 Share on other sites More sharing options...
pleek Posted December 8, 2008 Author Share Posted December 8, 2008 i understand how to use var but i don't know how to check it with the file that is being uploaded. $filename = game.nes $filecheck = THE UPLOADED FILE NAME WITH EXTENSION if ( $filecheck != $filename) { echo' Only .nes games can be uploaded'; } what i don't know is how to get the name and extension of the file that is being uploaded to set it to $filecheck. Now do you get where im stuck? and by "in the manual" do you mean the $_file link post earlier? cause when i tried $_FILES['userfile']['type'] i was told i was doing something wrong and not setting the var correctly. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-710005 Share on other sites More sharing options...
.josh Posted December 8, 2008 Share Posted December 8, 2008 Now do you get where im stuck? and by "in the manual" do you mean the $_file link post earlier? cause when i tried $_FILES['userfile']['type'] i was told i was doing something wrong and not setting the var correctly. EXACTLY. In the manual, the example is 'userfile' because in their example form they have Send this file: <input name="userfile" type="file" /> You need to insert your own variable name in $_FILES['YOUROWNNAMEHERE'][...] : The one you used in your form. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-710032 Share on other sites More sharing options...
pleek Posted December 8, 2008 Author Share Posted December 8, 2008 ahhhh, ok thank you very much. I really appreciate you being pacient with me. I think i now have it figure out and i will post what i come up with or if i have any more problems. Thank you again. Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-710050 Share on other sites More sharing options...
pleek Posted December 9, 2008 Author Share Posted December 9, 2008 now that you explained that both checks are working. thanks a lot guys!!!!! <?php $target_path = "Games/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $file = "3DWORLD.NES"; if($_FILES['uploadedfile']['name'] == $file) { echo'the files are the same<BR>'; } if ($_FILES['uploadedfile']['type'] == "application/octet-stream") { echo "the file is a .NES<BR>"; } if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/135967-solved-uploaded_type-help/#findComment-710112 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.