Uploading files to mysql

Reply

Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Uploading files to mysql

 
0
  #1
Feb 26th, 2009
hi,

I am trying to learn how to upload multiple Music files to server then save information about them in database e.g. albumname, filename, type and maybe url. i have few questions:

1. would i be able to write the albumname in database as the folder i am uploading to. if so how?

2. how would i upload multiple files..

as i am a newbie can you guys please show me an example of this...

thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Uploading files to mysql

 
0
  #2
Feb 26th, 2009
1. Yes. Since you know where you will be uploading the file, you can save the foldername as albumname
2. By using multiple <input type='file' > tag

I am not sure if the examples in these links work, but, this is how you do it.
http://www.phpeasystep.com/workshopview.php?id=2
http://www.plus2net.com/php_tutorial...ile_upload.php
Last edited by nav33n; Feb 26th, 2009 at 8:49 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 60
Reputation: Andrieux is an unknown quantity at this point 
Solved Threads: 4
Andrieux Andrieux is offline Offline
Junior Poster in Training

Re: Uploading files to mysql

 
0
  #3
Feb 26th, 2009
It's not as hard as you'd think.

Say that that you're creating a Pastebin. You'd have (simplified) the fields id, title, and filename. The filename could be random. For our purposes, $input is what the user is saving in the document, $title is the title, and we'll create the filename.
  1. <?php
  2.  
  3. $title = mysql_real_escape_string($title);
  4. $filename = rand(1,1000) . substr(0, 5, time());
  5.  
  6. mysql_query("INSERT INTO `pastebin`(title, filename) VALUES('$title', '$filename')");
  7.  
  8. $fh = fopen($filename . ".txt", +w);
  9. fwrite($fh, $input);
  10. fclose($fh);
  11.  
  12. ?>

Of course, that's just creating it.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 257
Reputation: sam1 is an unknown quantity at this point 
Solved Threads: 1
sam1's Avatar
sam1 sam1 is offline Offline
Posting Whiz in Training

Re: Uploading files to mysql

 
0
  #4
Feb 26th, 2009
I got the answer to second question basically i will pass the id of textbox to insert.

but how would i actually write the url dynamically upon uploading, to database. say i am uploading into a folder called 'album1' 5 mp3s. now how would i insert in database album1/mp3.mp3, without hardcoding it like $path = "album1";
Last edited by sam1; Feb 26th, 2009 at 11:01 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Uploading files to mysql

 
0
  #5
Feb 26th, 2009
but how would i actually write the url dynamically upon uploading, to database. say i am uploading into a folder called 'album1' 5 mp3s. now how would i insert in database album1/mp3.mp3, without hardcoding it like $path = "album1";
Check move_uploaded_file . You have to specify the 'destination' where you want to upload the file. Use the same destination Right ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC