Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    upload mp3 file only

    I am trying to upload mp3 files only, but this code seems to allow any file type (I have tried both mp3 and jpg/gif)

    Can someone show me what I am doing wrong?

    PHP Code:
    <?php
    if($_POST['submit']=="Upload") {
        if (
    $_FILES['file']['name'] != "") {
            
                if (
    eregi("\.mp3$"$_FILES['file']['type'])) {
                    echo 
    "Please upload an mp3!<br /><br />";
                    echo 
    "<a href=\"mp3upload.php\" title=\"Back to Uploads\">Go Back</a>";
                    exit;}
            if (
    $_FILES["file"]["size"] < 2000000) {
                
                    
    move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" $_FILES["file"]["name"]);
                   echo 
    "File has been stored in your uploads directory.";
    }} else {
        echo 
    "Please upload a file that is under 2 mb!";
    }
    }
    ?>
    Thanks in advance.
    Last edited by bfsog; 07-26-2005 at 04:32 PM.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Try using
    PHP Code:
    if($_FILES['file']['type'] == "audio/mpeg"

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Yeah Nightfire is on the right track, if that still doesn't work right, you could always have it print out of the value of the type property when you upload an MP3 so you can see what it shows up as.

    Also, one minor thing I noticed was that you say upload a file under 2mb yet your code it set to block files bigger than 1.9mb, it probably wouldn't be a huge issue but if you want to make to more exact, it really should be:
    PHP Code:
    if($_FILES["file"]["size"] < 2097152) { 
    Since there are 1024 bytes in one kilobyte and all.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •