If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Uploading and downloading music files to and from Mysql

Hello there

I have to make a website with a database for a CS class at university that allows the user to search for a piece of music or a particular sound effect, preview the media and then have the option to download or implement another search.

My issue is how do I go about uploading the music/fx files to MySQL, and then retrieving them?

In terms of populating my web page with the items from the database I know can do that by using tables but in terms of getting the files into the db via the webpage, this is still a bit confusing to me.

I've seen somewhere that I need use filetype blob/longbow which will house the file location of the media file but they didn't go into great detail on how to do this or in fact what a blob is.

I have to make a website with a database for a CS class at university that allows the user to search for a piece of music or a particular sound effect, preview the media and then have the option to download or implement another search.

My issue is how do I go about uploading the music/fx files to MySQL, and then retrieving them?

In terms of populating my web page with the items from the database I know can do that by using tables but in terms of getting the files into the db via the webpage, this is still a bit confusing to me.

I've seen somewhere that I need use filetype blob/longbow which will house the file location of the media file but they didn't go into great detail on how to do this or in fact what a blob is.

Any help would be massively appreciated.

Thanks in advance

Is there any reason you want to store the file in the database?
I would store the file name, author, other information in the database, but put the MP3 itself just somewhere usually not reachable on the server. Then store that location in the database too.

My general rule: databases are for storing data, while filesystems are for storing files.

You typically end up creating a server-side program that is your file server. So your application code would, upon doing whatever database stuff, etc., provide the user with a link to that file server file that includes the necessary ID field or whatever to identify the desired file. Then that script would look up the file path-name info in the DB, set the applicable HTTP headers, and read/output the file. In a rather over-simplified PHP script (very little defensive coding, no user auth, etc.):

Is there any reason you want to store the file in the database?
I would store the file name, author, other information in the database, but put the MP3 itself just somewhere usually not reachable on the server. Then store that location in the database too.

I understand this but I wanted some detailed help on how to go about this if possible.

My general rule: databases are for storing data, while filesystems are for storing files.

You typically end up creating a server-side program that is your file server. So your application code would, upon doing whatever database stuff, etc., provide the user with a link to that file server file that includes the necessary ID field or whatever to identify the desired file. Then that script would look up the file path-name info in the DB, set the applicable HTTP headers, and read/output the file. In a rather over-simplified PHP script (very little defensive coding, no user auth, etc.):

Are you saying the actual music files when uploaded by the user will then got to the file system with the details going to the database?

If this is the case then when the user wanted to retrieve a particular music file, after they implemented a search, how would the results show on the web page? Would the link to the file be generated from the database?

Also could you possibly explain further the concept of the file system in this instance, could I use something like filezilla and if so how would I go about this?

Sorry if this is a stupid question just need clarification before I start to implement. Thanks very much by the way, to both of you.

Unfortunately download= is not yet supported in all browsers, and there is a little more cleaning to do around the place, however this is the very basics of a very basic version where you're not trying to limit access to files.

If you really wanted to limit file access you could use a better version of:

Unfortunately download= is not yet supported in all browsers, and there is a little more cleaning to do around the place, however this is the very basics of a very basic version where you're not trying to limit access to files.

If you really wanted to limit file access you could use a better version of:

Just one last thing what NogDog was talking referring to re the actual MP3 being stored in a file system and the database just housing the MP3 info as it were, is that how I go about it? Couldn't it work with just having the file location of the mp3 in the database (mysql) as a blob or longblob?

If you store it as a blob in the DB, every time someone downloads a "file", every single byte has to be pulled from the DB into the application (often on different servers) before being put into the output stream; so the main reason I don't like doing that is the unnecessary load it puts on the DB. It can be done, and there may even be some good reasons to do it in some situations -- but I can't really think of any off-hand. Also, it may require some mucking about with the database configuration to allow it to transfer that much data for one request.

"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation

Just one last thing what NogDog was talking referring to re the actual MP3 being stored in a file system and the database just housing the MP3 info as it were, is that how I go about it? Couldn't it work with just having the file location of the mp3 in the database (mysql) as a blob or longblob?

Thanks again Gravy your help has been invaluable.

Yes, that's what he was talking about, just having the MP3's as normal files stored on the server and not in the database.
Having the file location in the database is exactly what I mean, however I wouldn't store it as anything as long as a blob or longblob.

I would honestly keep the filename stored in the database as a simpler varchar, which can have up to 256 characters, enough length for any file I've ever (in any sane, non-harddisk crashing situation) encountered.

I would also change the filename when storing it to a simple number.mp3, this can save you heartache in the future when you come across unusual file names, such as 我的音乐.mp3 which suddenly causes problems between the browser, php, mysql, and the os communicating happily. PHP and windows don't communicate well with file names of some foreign languages.

==== OFF ON A TANGENT ====
I always prefer to set my databases to (I think it's) UTF8-general-ci, so it can store pretty much any character and set my page meta tags to UTF-8.

PHP Code:

<meta charset="utf-8">

Then again that's a whole different story.
==== OFF OF MY TANGENT ====

So I often prefer to use the id of the database entry for the file name, and add the .mp3 to the end too. It also removes having to think about various other security issues such as dodgy file names and such.

You could do it either way, since I work in foreign languages quite a lot, I end up getting these type of bias'. Also make sure if users are uploading files, to make sure they can only upload .mp3 files, and not .php files and other such scary file types.

Yes, that's what he was talking about, just having the MP3's as normal files stored on the server and not in the database.
Having the file location in the database is exactly what I mean, however I wouldn't store it as anything as long as a blob or longblob.

I would honestly keep the filename stored in the database as a simpler varchar, which can have up to 256 characters, enough length for any file I've ever (in any sane, non-harddisk crashing situation) encountered.

I would also change the filename when storing it to a simple number.mp3, this can save you heartache in the future when you come across unusual file names, such as 我的音乐.mp3 which suddenly causes problems between the browser, php, mysql, and the os communicating happily. PHP and windows don't communicate well with file names of some foreign languages.

==== OFF ON A TANGENT ====
I always prefer to set my databases to (I think it's) UTF8-general-ci, so it can store pretty much any character and set my page meta tags to UTF-8.

PHP Code:

<meta charset="utf-8">

Then again that's a whole different story.
==== OFF OF MY TANGENT ====

So I often prefer to use the id of the database entry for the file name, and add the .mp3 to the end too. It also removes having to think about various other security issues such as dodgy file names and such.

You could do it either way, since I work in foreign languages quite a lot, I end up getting these type of bias'. Also make sure if users are uploading files, to make sure they can only upload .mp3 files, and not .php files and other such scary file types.

Was trying to run some basic php scripts yesterday to test uploading a file and I was finding even though the tests I did that test connections worked it seems that when I ran the scripts nothing happened. I didn't even get an error message.

Now I'm using phpmyadmin and it seemed that I everything was correct in the setup but still nothing is happening.

This scripts are below.

Is it possible that it could be a problem with the config.inc.php file? Oh I'm using XAMPP by the way.

you shop it like a blob within the DB, each time somebody downloads a "document", each byte needs to be drawn in the DB in to the software (frequently on various machines) before being put in the output flow; therefore the major reason I actually don't like doing that's the needless weight it places about the DB. It may be completed, and there might even be good quality reasons to complete it in certain circumstances -- but I can not think of any off hand. Additionally, it might need some mucking about using the database setup to permit it to move that much information for just one request

Hey guys trying to get this audio uploading script to work but I can't seem to get anything into the database. I think something may have gone awry with my variables perhaps. Could you possibly point out where I'm going wrong if you can see it that is. Feel like my brain is melting
Thanks v.much as always

Hey guys trying to get this audio uploading script to work but I can't seem to get anything into the database. I think something may have gone awry with my variables perhaps. Could you possibly point out where I'm going wrong if you can see it that is. Feel like my brain is melting
Thanks v.much as always

Hey guys trying to get this audio uploading script to work but I can't seem to get anything into the database. I think something may have gone awry with my variables perhaps. Could you possibly point out where I'm going wrong if you can see it that is. Feel like my brain is melting
Thanks v.much as always