Is it possible to check the length of a .mp3 file ?

I have used the getimagesize($_FILES['upload']['tmp_name']); to check the width and height of a profile photo before upload.
And now I need musicians to be able to upload sound clips in mp3 format to their profile. But according to the low a sound clip must last a maximum of 45 seconds. So is it possible to check this before upload or after upload ?

    I dont think you can chack the actual length with php, the size yeah. Has your server got python installed per chance? There are a few python libraries around that could do this easily.

      You can probably invoke a helper application on the server, sox appears to be helpful.

      For example,

      sox stat infile.wav outfile.wav
      

      Converts infile.wav to outfile.wav, producing some stats on stdout (including the length). I don't know how to (obviously) do this without making an output file (you could of course output to /dev/null or a junk file).

      Maybe another helper will do

      Mark

        This sounds very advanced. I don't think I'm at that level :o)

        So if anyone has a solution, maybe from the above info, that a beginner can find out it would really help.

        But thanks for your input, and I hope someone can give the last building stones.

          DISCLAIMER: This isn't an easy way to do this. 🙂

          Isn't the length stored within most audio files (e.g., MP3s)? Does anyone know if the length is in ASCII or not?

          At worst, if you could find out the specific location and format of it, you could search the file in binary mode to grab the length.

            www.getid3.org does bitrate, length and id3 tag reading and rewriting.

            it's a very nice tool - i use it to rewrite the title tags etc after someone has uploaded to my server.

            hope this helps.

              So if I understand it correctly, I need to upload some program on my server to do it ?

                To quote the 'getID3' link posted above,

                getID3() is a PHP4 script...

                EDIT: I stand corrected - there are dependencies of that program... lots of em. My mistake =\

                  Write a Reply...