How to load .mp3 file in php only after checking, my .wav file loads 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;
    }
}

      

+3


source to share


3 answers


just print $_FILES["myfile"]["type"];

for a real mp3 file then copy the value and use it instead of audio / mp 3 because the MIME type of mp3 will not be "audio / mp3" I guess itsaudio/mpeg



Please check this Link because it is not recommended to depend on $_FILES["myfile"]["type"]

that sent by the browser.

+2


source


Two things.

Check the size of your file .mp3

. Check the file type .mp3

if it is valid audio/mp3

. Try it 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.

0


source


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

0


source







All Articles