2 Replies - 952 Views - Last Post: 13 June 2012 - 02:42 PM Rate Topic: -----

#1 jwag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 01-April 12

check file uploading is audio file

Posted 13 June 2012 - 12:01 PM

hey, i got a form uploads files from users computer, but i want to check if the file is mp3 or any audio. ill worry about the id3's later, but any file i try to upload, this if statement catches it, even if it is correct, i echoed out an audio file i tried to upload and it displayed this as the file type
audio/mp3

the if statement is this
	else if($theFileType != "audio/mpeg"||$theFileType != "audio/mp4"||$theFileType != "audio/mp3")
		{
			print '<script type="text/javascript">'; //this opens javascript
			print 'alert("Hey, you can only upload media files!")'; //alert says this
			print '</script>'; //end
			print '<script type="text/javascript">'; //this opens javascript
			print 'window.location = "index.php"';//redirect
			print '</script>'; //end
		}


Is This A Good Question/Topic? 0
  • +

Replies To: check file uploading is audio file

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: check file uploading is audio file

Posted 13 June 2012 - 12:31 PM

Think about it. The || operator means OR, so to write that code in a more human-readable way:
if (it's not MPEG || it's not mp4 || it's not mp3) {
    // Invalid
}
else {
    // Valid
}


Which means that the file must be all three types, or it will end up in the "Invalid" block.

You want to be doing something more like this:
if (it's MPEG || it's mp4 || it's mp3) {
    // Valid
}
else {
    // Invalid
}



By the way:
print '</script>'; //end
print '<script type="text/javascript">'; //this opens javascript


What would be the point in these two lines?
Was This Post Helpful? 2
  • +
  • -

#3 jwag  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 01-April 12

Re: check file uploading is audio file

Posted 13 June 2012 - 02:42 PM

View PostAtli, on 13 June 2012 - 12:31 PM, said:

Think about it. The || operator means OR, so to write that code in a more human-readable way:
if (it's not MPEG || it's not mp4 || it's not mp3) {
    // Invalid
}
else {
    // Valid
}


Which means that the file must be all three types, or it will end up in the "Invalid" block.

...

yay it works! thanks =D, i feel kinda dumb now...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1