Forums

Writing file name & form field to text file. Help

yukon 14 Jun, 2008
I have a form that allows users to upload a file and give it a title. My question is, how can I get the file name that is uploaded and the title field to be written/appended to a text file.

Any help would be appreciated.
yukon 14 Jun, 2008
OK, after a little hacking around, I'm managed to get the original file name that was uploaded, but what I really need is to get the filename after the image is processed and moved to the upload folder.

So instead of getting file with name "21.jpg"
I need to get the full name after it's moved. Like "2008289348958_21.jpg"

Is that possible?
GreyHead 17 Jun, 2008
Hi yukon,

At the OnSubmit processing step the form information is in two separate places.

The new form names and paths are in the $attachments array and can be accessed though:
$attachments['field_name']
This will give you a result like

D:\xampp\htdocs\joomla1.5/components/com_chronocontact/upload/20080617151517_test_doc.pdf

This is the entry value you need to use to link to the file using a folder path. If you just want the file name then you need to use:
basename($attachments['field_name'])


The file type and size are accessible from the $_FILES array as
$_FILES['field_name']['size']
$_FILES['field_name']['type']


Bob
Becca800 03 Oct, 2008
I am trying to use this. I am using the submitcontent form. I have created a javascript to go along with my form which takes all the information from the form elements and inserts it all into the html for the main body of the article. It works great. But I am unable to get the image name of the upload. Since it is a js script, I converted the php variable to a js variable. Then I referred to it in the script. The problem is, the js script works on a onblur event. When that happens, it causes the php script to run and I suddenly get a blank screen on the first form entry. I don't know how else I can do it without having to create a second form. Any thoughts?
Max_admin 03 Oct, 2008
Hi Becca,

if JS can't get the file name (I'm not sure of this because I never tried it) then you may need AJAX to mix the PHP and JS without submitting the page, J1.5 comes with mootools so you better use the mootools AJAX class, very easy to use, you can download ChronoComments and open scripts.js file and see near the end how the mootools AJAX calls gets executed!

but another issue comes to my mind now, I didn't try before getting a file name from a file field with AJAX too!😟 so not sure if AJAX will do it even if it looks the best way to solve the PHP/JS lock you have!

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.