Page 1 of 1

file upload / don't upload on edit form

Posted: Thu Jan 21, 2010 5:38 pm
by loudrake
I currently have 2 forms, add_file.php and edit_file.php. If I have already added a file and description, then need to edit the description of that file how can I edit only the description without reuploading the file again. Currently if I don't browse and upload the file again on my edit_file.php form nothing is entered in the FILE_NAME field of the database (instead I want the original FILE_NAME to remain).

Currently I just do the following, how can I edit this to prevent me from uploading the image everytime?

<input type="file" value="<?=$FILE_NAME ?>" name="myfile" />

thnx in advance.

Re: file upload / don't upload on edit form

Posted: Thu Jan 21, 2010 7:04 pm
by Hieroglyphics
Make another input that automatically changes to the filename after it is loaded using ajax, and let the user choose to change it, because it will be a text input box not file.

Re: file upload / don't upload on edit form

Posted: Thu Jan 21, 2010 10:33 pm
by loudrake
Not sure I follow completely.

1. I create a new input that is a text field instead of a file, populate that from the database with the FILE_NAME. If the user does not change the file name then it resends the original name to the database field and the file remains the same.

2. But what happens if they do want to change the file? If the new input is now a text field it prevents a new file from actually being uploaded, all I can do it allow the name of the file to be changed. (This is the part I'm not understanding obviously).

Re: file upload / don't upload on edit form

Posted: Fri Jan 22, 2010 12:10 am
by Hieroglyphics
I'm sorry, I don't understand :( hopefully somebody else can answer this question.

Re: file upload / don't upload on edit form

Posted: Fri Jan 22, 2010 1:30 am
by rajeevbharti
firstly if you are using javascript for validation then remove it and submit the file and set update the database table with only description .it will update only description and left other as it is.

Re: file upload / don't upload on edit form

Posted: Fri Jan 22, 2010 7:33 am
by loudrake
Let me step back. On my edit_file.php form there are several fields but lets keep it simple and say there are only two, "DESCRIPTION" and "FILE_NAME". If the file has already been uploaded and I want to go back and just update the DESCRIPTION I currently have to also upload the file or it leaves the FILE_NAME field empty in the database.

I can get around that by changing the input from file to text BUT then what if I do want to upload a new file at some point in time? I can't do it through a text field.

Isn't there a way to do an IF statement on that input file telling the form if NEW_FILE_NAME = '' then leave the OLD_FILE_NAME in the database field?