Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

mp3 upload not work on server side using php

I have mp3 upload form. When i upload my project on server the mp3 upload not work, i echo file name, size and tmp_name, it return file size is 0 and tmp_name is blank. But when upload jpg image i got file name, size, tmp_name.

What i tried code mention in below: upload Form:

<form class="needs-validation row" id="add-form" enctype="multipart/form-data">
    <input type="file" id="audio" name="audio" class="form-control">
    <button id="btn-submit" class="btn btn-primary" type="submit" ><i id="addclasses" class="fa fa-check"></i> Submit</button>
    <span class="error" style="color:red;"></span>
</form>

Ajax call code:

<script>
$("#add-form").on('submit', (function(e) {
    event.preventDefault();
    $.ajax({
          type: 'POST',
          data: new FormData(this),
          url: 'add-form.php',
          cache: false,
          contentType: false,
          processData: false,
          success: function(response) {
            if(response == 1){
                $('.error').html("<span>File upload successfully</span>");
            }else{
              $('.error').html(response);
            }
          }
      });
}));
</script>

and my server side code:

<?php

echo $_FILES['audio']['name'].'<br>';
echo $_FILES['audio']['tmp_name'].'<br>';
echo $_FILES['audio']['size'];
exit();
?>

here is referance link file upload


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Likely that your audio file size is too large. Please change your settings (either by changing your php.ini, or add the below directives to the top of your upload server side script):

ini_set('memory_limit', '40M'); 
ini_set('max_execution_time', 80000); 
ini_set('post_max_size', '40M'); 
ini_set('upload_max_filesize', '40M'); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...