Search code examples
phphtmlmysqlphpmyadminmp3

phpMyAdmin - How to save mp3 files in database?


I am programming a website where I need to store mp3 files in a database. I am using phpMyAdmin and mySQL for my database and am programming the website using html/php/css/javascript.

After doing some research, I have found that a good method for doing this is to not to store the actual mp3 file in the database, but to store the path to the file and to store the mp3 file on the "filesystem".

I am new to web development, so what do people mean by "filesystem" and how would I save/retrieve an mp3 file to the "filesystem"?


Solution

  • Say your users upload files to your server (like you do when you add an image to Facebook, or any other site). In your case, mp3-files. These files are stored on your server - either in one general folder, or in subfolders belonging to each user (the latter might be better to avoid people uploading files with the same name, overwriting other files, etc.) - your upload script needs to put these files where you want them AND store this path with the file-name in the database. Technically, if you know the file-path beforehand (which you should do), all you need to store in the database is the fileNAME.

    That being said - you might not need to store files or filenames in the database at all. You can just read the folders (would need a folder per user, probably) and parse the files found in the folders, and show those.

    Your level of knowledge seems maybe a little less than what I would recommend for something like this (there are a lot of pitfalls allowing people to upload files to your server, if that's what you're planning on doing), and you might wanna train a bit, learn a bit more, before doing something like this.

    At least I would recommend perhaps using a ready-made upload script to help you with the logistics.