sidhesh
sidhesh

Reputation: 107

How to upload .mp3 file in php only after validation,my .wav file gets uploaded easily

if ((($_FILES["myfile"]["type"] == "audio/mp3") ||
     ($_FILES["myfile"]["type"] == "audio/wav")) &&
    ($_FILES["myfile"]["size"] < 20000000)) 
{
    if (move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path) )
    {
        $result1=1;
    }
}

Upvotes: 3

Views: 4638

Answers (3)

Mevin Babu
Mevin Babu

Reputation: 2475

You can check by evaluating the extension of the uploaded file or if you want to check file level then you can one of the pear packages https://pear.php.net/package/MP3_ID

Upvotes: 0

web-nomad
web-nomad

Reputation: 6003

Two things.

Check the size of your .mp3 file. Check the file type of your .mp3 if it is actually audio/mp3. Try print_r($_FILES);.

$type = $_FILES["myfile"]["type"];
$size = $_FILES["myfile"]["size"];

if( ( ($type == "audio/mp3") || ($type == "audio/wav") ) && ($size < 20000000)) {
    if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path) ) {
        $result1=1;
    }
}

Hope it helps.

Upvotes: 0

user1646111
user1646111

Reputation:

just print $_FILES["myfile"]["type"]; for real mp3 file then copy the value and use it instead of audio/mp3 because MIME type of mp3 will not be 'audio/mp3', i think its audio/mpeg

Please check this Link also, because its not recommended to depend on $_FILES["myfile"]["type"] that send by browser.

Upvotes: 2

Related Questions