[solved]Weird problem upload routine.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

[solved]Weird problem upload routine.

Post by dreamline »

Hi Guyz,
I've written an upload routine for MP3's. It's nothing special, but it seems that some people get an error (File is not an MP3) while the file is OK. When people send me the file through email and i upload it myself there isn't any problem and the routine works just fine. You can see the checking code below.

Anybody know of a glitch what can cause the above problem.

Code: Select all

if (is_uploaded_file($_FILES['mp3file']['tmp_name']))
  {
   $filetype = $_FILES['mp3file']['type'];
   $filesize = $_FILES['mp3file']['size'];
   $filename = $_FILES['mp3file']['name'];
   if (($filetype == "audio/mpeg") || ($filetype == "audio/mpeg3") || ($filetype == "audio/x-mpeg-3"))
     {
     if (!ereg(".mp3",$filename))
      {
      Echo("Error wrong extension");
      }
   }
   else
   {
   Echo("Error file is not a MP3");
   }
Last edited by dreamline on Mon Dec 26, 2005 8:05 pm, edited 1 time in total.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Your best bet at tracking down the problem is to change your error line to this...

Code: Select all

Echo("Error file is not a MP3 - Detected Filetype: $filetype");
This way it will display the filetype so the person reporting the problem can tell you exactly what the server thought was being sent.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Thanks, i'll give it a go.. :)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Most likely their browser isn't sending the mime type, check it manually http://us3.php.net/manual/en/function.m ... t-type.php
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

K, i implemented to see if the mime type is actually sent, so hopefully this will get me an insight of what mime type is actually sent.

If i know that then i can follow your instructions jshpro2... :)

Thanks to both for helping.. :D
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

On one of my forums I allow mp3 uploads, here is a list of all the mime types that different browsers have sent for 3,456 uploaded mp3 files for ring tones.


audio/mpeg
audio/mpeg3
audio/x-mpeg3
audio/mpeg-url
audio/x-mpeg-url
application/x-mp3



yj
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Thanks for the mime types, i'm most definately not using a few of them.... :)
Post Reply