943,746 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3024
  • PHP RSS
Feb 26th, 2009
0

Uploading files to mysql

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Feb 26th, 2009
0

Re: Uploading files to mysql

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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Feb 26th, 2009
0

Re: Uploading files to mysql

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.
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Andrieux is offline Offline
60 posts
since Jan 2009
Feb 26th, 2009
0

Re: Uploading files to mysql

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.
Reputation Points: 10
Solved Threads: 1
Posting Whiz
sam1 is offline Offline
300 posts
since Nov 2004
Feb 26th, 2009
0

Re: Uploading files to mysql

Quote ...
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 ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Looping through results query!
Next Thread in PHP Forum Timeline: Ending Sessions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC