Welcome to Dream.In.Code
Become a PHP Expert!

Join 149,988 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,371 people online right now. Registration is fast and FREE... Join Now!




audio file

 
Reply to this topicStart new topic

audio file, store audio file

chitara
13 Nov, 2006 - 07:31 PM
Post #1

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
I am going to make a jukebox in php & mysql.

1. There will be a option to upload/store music according to the category.

2. User will be able to create a play list accoding to their choice.


Can anyone please tell me how can I store audio file??


Regards
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Audio File
13 Nov, 2006 - 07:34 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,355



Thanked: 51 times
Dream Kudos: 25
My Contributions
Perhaps I'm not understanding the question...are you asking for a script that uploads files? Storing the audio is as simple as uploading the file to a specific directory. You can then put an entry into a database that holds the path to that file, along with some information about categories. Or are you looking to store the file in some special circumstances?
User is offlineProfile CardPM
+Quote Post

chitara
RE: Audio File
13 Nov, 2006 - 07:51 PM
Post #3

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
Thanks Amadeus

ok, Let me try it first.

Regards
User is offlineProfile CardPM
+Quote Post

chitara
RE: Audio File
19 Nov, 2006 - 09:26 PM
Post #4

D.I.C Head
**

Joined: 16 Dec, 2005
Posts: 74


My Contributions
Hi

I tried to upload the music file same as the image file. but its not getting stroed.

*My action file is as follows-act.php >>

CODE
<?
$dir= "musiclib/";
include "admin/include/db.php";

// To get User Id
$query=mysql_query("select * from musiclibrary");
$count=mysql_num_rows($query);
$id=$count+1;
echo $id;

// List of our known photo types
//    $known_photo_types = 'audio/mp3 -> mp3';
    $known_file_types = array(
                        'audio/mp3' => 'mp3',
                        'audio/mpeg' => 'mpeg'
                    );
    
    
    
$music_uploaded = $_FILES['musicfile'];
if(!array_key_exists($music_uploaded['type'], $known_file_types))


            {
                echo "Sorry this file is not supported by this module<br />";
            }
            else
            {
$sql=mysql_query("insert into musiclibrary (music_no, music_name, file_name, music_day, cat_id) values('$id','test', '0', '0', '103')");
$result = mysql_query($sql);

                $new_id = $id;
                $filetype = $music_uploaded['type'];
                $extention = $known_file_types[$filetype];
                $filename = $new_id.".".$extention;
                
                mysql_query( "UPDATE musiclibrary SET file_name='".addslashes($filename)."' WHERE music_no='".addslashes($new_id)."'" );
                
                // Store the image file    into the image directory            
                copy($music_uploaded['tmp_name'], $dir."/".$filename);

            }
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=act.php\">";
}

mysql_close();
?>

<a href=file.php>back to stor another file</a>



And here is the form >> file.php

<form enctype="multipart/form-data" action="act.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="musicfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>



my table is like..

CODE
CREATE TABLE `musiclibrary` (
  `music_no` int(11) NOT NULL auto_increment,
  `music_name` varchar(100) default NULL,
  `file_name` varchar(100) default NULL,
  `music_day` decimal(10,0) default NULL,
  `cat_id` decimal(10,0) default NULL,
  PRIMARY KEY  (`music_no`),
  UNIQUE KEY `music_no` (`music_no`),
  KEY `cat_id` (`cat_id`)
);


One more thing, when I try to upload any audio file its showing "Sorry this file is not supported by this module".

Please tell me why??

[mod edit] please please use code tags!

This post has been edited by hotsnoj: 20 Nov, 2006 - 10:18 AM
User is offlineProfile CardPM
+Quote Post

Tuzoid
RE: Audio File
20 Nov, 2006 - 06:09 AM
Post #5

D.I.C Head
Group Icon

Joined: 20 Aug, 2006
Posts: 120



Thanked: 2 times
Dream Kudos: 50
My Contributions
Hmm, I'm not near a good editor. But the if statement where this error is coming from could be:
CODE

// List of our known photo types
// $known_photo_types = 'audio/mp3 -> mp3';
$known_file_types = array(
'audio/mp3',
'audio/mpeg'
);



$music_uploaded = $_FILES['musicfile'];
if( !in_array( $music_uploaded['type'] , $known_file_types ) )
{
echo "This file is not supported!";
}


I'm not anywhere near a text editor, I'm making this with the reply box...If this isn't right, I apologize.

If you need any more help, please ask!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 07:45PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month