0

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

Milind Bhuvad
  • 43
  • 3
  • 10
  • can you show screen of network from devtools? I think that error happens there, because you can check that form load sounds correctly in my other answer https://stackoverflow.com/questions/38195855/how-to-create-an-arraybuffer-and-data-uri-from-blob-and-file-objects-without-fil/65500931#65500931 – Daniil Loban Dec 31 '20 at 15:38

1 Answers1

1

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'); 
Ken Lee
  • 6,985
  • 3
  • 10
  • 29