Official Luthiers Forum!
http://w-ww.luthiersforum.com/forum/

Does anyone here know PHP?
http://w-ww.luthiersforum.com/forum/viewtopic.php?f=10102&t=13781
Page 1 of 1

Author:  James Orr [ Tue Sep 25, 2007 3:47 pm ]
Post subject: 

Hi everyone

I'm working on a project that's asking me to dwelve into skills I happily
moved to the recesses of my mind. I'm building a PHP form that will have
a file upload function. I'd like to "echo" the name of the uploaded file into
another field. So I'm trying to do something that will look like this:

Upload file: upload button

mp3: text field

I'd like the uploaded file to automatically echo its name into the mp3's
text field.

The bigger picture is an audio player in flash for my church. They'll
upload the file, enter it's display information, and be done with it. The
form will add the info to a database, and another form will read the
database, compile it all into an XML array which Flash reads.   

Right now what I can do is upload the file, go to a new page upon
completion to enter the data and select the file from a drop down list. I'd
like to make it a one page, non drop down deal for efficiency and less
chance of user error.

Author:  Richard Wilson [ Wed Sep 26, 2007 12:07 am ]
Post subject: 

So you want to click the "Browse..." button on the upload box, find the filename, click "Open" and have that filename appear automatically in a box below? I assume the idea is that if the filename is incorrect for the mp3 (track01.mp3, rather than the desired Artistname - Trackname.mp3), the person uploading will be able to edit what the text is, but to cut down time it'll automatically appear?


If this is the case, it'll be playing with some Javascript, in which case try Googleing along those lines ('javascript update form field from another' etc.). The key will be getting it to strip everything but 'filename' from 'C:/path/filename.mp3'


If all you want to do is get the just the filename.mp3 to save into a database, then it'll be a simple use of the basename( $_FILES['upload_field_name']['name']) after submitting to extract the filename, and using that in the appropriate SQL query.


Hope this helps... it beats actually getting to work on redoing my site.


Author:  James Orr [ Wed Sep 26, 2007 5:33 am ]
Post subject: 

Richo, thank you! The second example is perfect, even if it doesn't totally
make sense. I'm sure I'll ask you another question!

I can already upload the file and change the info. I'm trying to get that
filename into the database along with the other display info.

Thanks again!

Author:  Richard Wilson [ Wed Sep 26, 2007 2:02 pm ]
Post subject: 

If you've got the upload working fine, then you will be using $_FILES[] probably a few times.


By using the basename() function around $_FILES['upload_field']['name'], it'll return just the 'filename.mp3'.


['upload_field'] will be whatever you've named the file upload field on the form. ['name'] just stays the same.


What I'd do is something like:


$filename = basename($_FILES['upload_field']['name'];


mysql_query("INSERT INTO songs SET (filename,etc.,etc.) VALUES ('$filename','$etc.','$etc.')");


Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/