Upload files and add to SQL?
Hi, I'm coding a LUA addon for a game, I'm streaming music to the game through my web server, and the list of songs is in a database with the fields: name, artist, album, min, and sec. I've managed to make a PHP script that adds those fields to the database, but then I have to go into the FTP, add the file in exactly the right place, etc. I was wondering if I could get some pointers on how to make an upload script that would take the fields I put in for the database, and make it upload to that directory, and add to the database at the same time. And example would be
Name: Test Song
Artist: That one guy
Album: The best one ever
Minutes: 3
Seconds: 24
Then I'd pick an mp3 and press 'Submit'. It would then upload that file to /That one guy/The best one ever/Test Song.mp3
I'd feel bad asking for someone to just hand me the code, so I'm asking for some good tips. I'm new to PHP and fairly new to SQL, and I'm sure this is pretty complicated, but any help would be greatly appreciated! Thanks in advanced :thumb:
Re: Upload files and add to SQL?
Here is a tutorial for creating a file upload script:
http://www.w3schools.com/PHP/php_file_upload.asp
Re: Upload files and add to SQL?
I got the file upload working, but I also need it to change where it uploads and add to the database. I put the database script in the upload script, and it gave me errors all over. Not sure why.
Re: Upload files and add to SQL?
well, if you have a script that you add songs to the database with already, you can just add a file upload to it and then save the file like that. you just have to create the directories, if they don't already exist, and then save the file in them. I'm not sure what you meant by "put the database script in the upload script," but if you meant it literally, then of course there would be errors! post some code.
Re: Upload files and add to SQL?
When you upload the file, record the file's path into a database.
I would also name the file something like:
Test_Song_currenttimestamp.mp3 and save that file name into the database to avoid writing over your current files.