简体   繁体   中英

How to upload mp3 file in php?

I am trying to upload mp3 file, but when i submit my file it give me error "Notice: Undefined index: audio/mpeg in E:\\xampp\\htdocs\\page_login\\mp3.php on line 7

Notice: Undefined offset: 1000000 in E:\\xampp\\htdocs\\page_login\\mp3.php on line 8"

Here is my code

 <?php
 include_once("connection.php");
 if(isset($_POST['submit']))
 {
 $file_name=$_FILES['file']['name'];
 $file_tmp=$_FILES['file']['tmp_name'];
 $file_type=$_FILES['file']['audio/mpeg'];
 $file_size=$_FILES['file']['1000000'];
 $insert=mysqli_query($connection, "insert into `file`(`audio`)values 
 ('".$file_name."')");
 move_uploaded_file($file_tmp, "image/".$file_name);
 echo "file upload";}   
?>
<form action="mp3.php" method = "POST" enctype="multipart/form-data"> 
<table border="2" width="10%" align="center">
<tr><th><input type="file" name="file"></th>
<th><input type="submit" name="submit" value="submit"></th></tr></table>
</form>

Just as the error states, there is no property on a $_FILES array entry called "audio/mpeg" :

$_FILES['file']['audio/mpeg']

(It would be pretty weird to have a property with that name on most files.)

There is , however, a property called "type" :

$file_type=$_FILES['file']['type'];

There's also no property called "1000000" , but there is one called "size" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM