SimonIoa 77 Master Poster

Hello i want to upload an audio file(.mp3). The file is uploaded on the folder, the value is inserted on the db (MySql) so far so good. But when i try to play the file on the uploads folder is says its corrupted or extension is wrong.the value is not base64 is the original name of the file

html

           <form [formGroup]="form" (ngSubmit)="onSubmit()"> <input type="file" name="avatar"     (change)="onFileSelect($event)" /> <button type="submit">Upload</button> </form>

ts

 onSubmit() {
const formData = new FormData();
formData.append('avatar', this.form.get('avatar').value);

this.group_id = 0;
this.media.tags = this.hashes;
this.media.audio = formData;
this.media.browser = true;
this.userData.uploadAudio(this.media, this.group_id ).subscribe(
  (res) => {
    this.uploadResponse = res;
      console.log(res);
  },
  (err) => {  
    console.log(err);
  }
);
 }

php

$mediaData = $request->post('media');
$name = $mediaData['audio'];
$uri =  substr($name,strpos($name,",")+1);
$encodedData = str_replace(' ','+',$uri);
try 
{
    $name = md5(time() . rand(1, 1000));
    if(!file_put_contents('uploads/' . $name.'.mp3', $decodedData)) 
    {
    }
}
catch(Exception $e)
{
}
$name = $name . '.mp3' ;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.