PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Thursday 11 September 2014

Upload audio using php and mysql

1 comment :
Today, I am going to show you one script for audio file uploads like mp3,wmv,mp4 etc..This is as easy as we upload image using php.We guys always go to site of songs to download our favourite singer songs.But how do these site allow user to upload audio is tricky.



But let us not waste time on discussing what they do.I am going to give you easy code for mp3 file upload.
the code is as below:

First we will create simple HTML code with form as below:

<form name="audio_form" id="audio_form" action="" method="post" enctype="multipart/form-data">
<fieldset>
<label>Audio File:</label>
<input name="audio_file" id="audio_file" type="file"/>
<input type="submit" name="Submit" id="Submit" value="Submit"/>
</fieldset>
</form>

Create one blank folder names "Audios" in your project to save audio files.

After Submitting form page will be redirect to same page.We can check file type using below:

<?php
if(isset($_POST['Submit']))
{
$file_name = $_FILES['audio_file']['name'];

if($_FILES['audio_file']['type']=='audio/mpeg' || $_FILES['audio_file']['type']=='audio/mpeg3' || $_FILES['audio_file']['type']=='audio/x-mpeg3' || $_FILES['audio_file']['type']=='audio/mp3' || $_FILES['audio_file']['type']=='audio/x-wav' || $_FILES['audio_file']['type']=='audio/wav')

$new_file_name=$_FILES['audio_file']['name'];

 // Where the file is going to be placed
$target_path = "Audios/".$new_file_name;

//target path where u want to store file.

//following function will move uploaded file to audios folder. 
if(move_uploaded_file($_FILES['audio_file']['tmp_name'], $target_path)) {

//insert query if u want to insert file
}
}
}

?>

In the Above code, $target_path is where you want to store file.
After successful execution of above code.you will be able to see your file uploaded in Audios file

1 comment :

  1. I have code it's seem to yours but it's doesn't send file to upload folder in server but it's send it to database without error but it's doesn't send to upload file????

    ReplyDelete