Text field that has a browse button for local file
Moderator: General Moderators
Text field that has a browse button for local file
Is there a way to have a text field that has a browse button next to it that will allow me to browse my local files and select them to be inserted into the text field?
Any help is greatly appreciated!
ljCharlie
Any help is greatly appreciated!
ljCharlie
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
the filename should be stored in the
Code: Select all
$_FILESї'yourfileupload']ї'name']What feyd said .. but if you're talking on the client side then the file type input 'area' is read only and can't be written to/altered, i don't even think JS can do it as it would present a rather large security hole (being able to change/decide what files get uploadedThat works; however, is there a way to truncate the location path and only keep the file name?
Thank you very much. So if it is not possible, how to do trim or break the location path from the file in PHP so I can store the location path and file name to the proper field in the database? For example, I have this:
C:\MyFiles\MyWork\Website\PDF_Files\All_goes_well.pdf
I want to store the PDF_Files\ into the Location field in my MySQL database and the All_goes_well.pdf into the File Name field. How do I break this location path from the file type text field from the client side once the user hit the submit button?
ljCharlie
C:\MyFiles\MyWork\Website\PDF_Files\All_goes_well.pdf
I want to store the PDF_Files\ into the Location field in my MySQL database and the All_goes_well.pdf into the File Name field. How do I break this location path from the file type text field from the client side once the user hit the submit button?
ljCharlie
Follow the examples here.
Note the <form enctype="multipart/form-data" ..... part of the form.
Note the <form enctype="multipart/form-data" ..... part of the form.
Many thanks for your help. That works. I didt use the $HTTP_POST_Files that's why it wasn't working. Anyway, I have another question. If I did as mentioned above, that means I just uploaded a file to my web server, correct? If that is true, then what directory or where on the server will the file be store? Basically what I want is just the path and file name and not uploading the actual file to the webs server. Will the above examples I posted cause whatever file I select to be uploaded to my webserver?
ljCharlie
ljCharlie
Okay, here's what I'm trying to do. I have an event page that with certain events it links to a registration pdf file that I already uploaded to a PDF/ directory on the webserver. On the MySQL database, I have two tables. One table contains all the information about an event such as date, description, place, and so on. The second table contains information about additional files that will link to the event such as the registration pdf file. So when the user view the event, they can click on that event's link and launch the registration pdf file on their screen. I use the second table to hold this information such as the file name, location of file on the server, and the eventID that will match the actual event on the event table. So, when I insert a new event into the event table on the MySQL database, and if this event happens to require a pdf file, instead of retyping the file name and location of the pdf file, I use the browse file to select the file on my location machine. Once I have that file selected along with all the other information for that event, I submit. When submit, I want to store the file name and path to its proper field in the second table on the database. I don't actually upload any file....although that I can if I don't already uploaded the pdf file ahead of time.
The only reason why I use the browse for file is because I don't want to type the pdf file name because it's possible to make mistyped.
ljCharlie
The only reason why I use the browse for file is because I don't want to type the pdf file name because it's possible to make mistyped.
ljCharlie
Well, you could always use glob or readdir (if you don't have PHP version 4.3.0 or above then you won't have glob) to get the list of existing registration pdfs (from the pdf directory on the server) and use that list to create a <select> box from which you can select the correct one to go with the event ?