ホーム

Send audio file to server - PHP

Let's send the audio file to the server using php. As logic, send an audio file to php at post from html form. php will receive it and send it to the server using the move_uploaded_file function. Before executing the move_uploaded_file function, use if to judge whether the sent file is an audio file. The whole code looks like this

class AudioFile 
{
    function check_audio_type()
    {
$updir = "./upload/";
$filename = $_FILES['upmusic']['name'];
echo $_FILES['upmusic']['type'];

if ($_FILES['upmusic']['type'] == "audio/wav") 
     {
        if(move_uploaded_file($_FILES['upmusic']['tmp_name'], $updir.$filename)==FALSE)
        {
          print("Upload faild");
        }
      }
   }
}

$audio_file  = new AudioFile ();
$audio_file->check_audio_type();

As for the implementation of the part that sends the audio file to the server, the sample code is posted in Qiita below, so I think that you can grasp the movements by reading it.

[urlpreviewbox url="https://qiita.com/Ryosuke-Hujisawa/items/2b0c358fa9920b5a5308"/]

-ホーム

Copyright© off , 2020 All Rights Reserved Powered by AFFINGER5.