Forums
This topic is locked
Optional file upload possible in forms?
Posted 26 May 2002 19:19:21
1
has voted
26 May 2002 19:19:21 Dries Coucke posted:
Hi,I've created a form with an upload file field and it works fine. But if there's no picture to upload, I'm redirected to my 'upload failed message' and the data of the form is not added to the database.
I cannot make this a mandatory field in the form, because there is not always a picture. The only solution I can think of now is creating a second form, but I'm open to other suggestions.
Thanks.
Dries
Replies
Replied 27 May 2002 11:10:31
27 May 2002 11:10:31 Tim Green replied:
You don't mention in your post whether you are using the standard insert record behaviors or not. Nor do you mention whether you use the PHP Upload behavior, or whether you have hand coded the script.
In either case, all you have to do is to specifically test for an empty field, and bypass the upload behavior accordingly, this will mean a little hand coding, but if your upload field is called <b>image</b>, for example, you just need to surround the PHP Upload Script with:-
if ($image != "" {
}
And the uploaded file will become optional.
Hope this helps.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
In either case, all you have to do is to specifically test for an empty field, and bypass the upload behavior accordingly, this will mean a little hand coding, but if your upload field is called <b>image</b>, for example, you just need to surround the PHP Upload Script with:-
if ($image != "" {
}
And the uploaded file will become optional.
Hope this helps.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 08 Jun 2002 01:55:44
08 Jun 2002 01:55:44 Dries Coucke replied:
Thanks, I use Phakt and the PHP upload behaviour. My upload field is called file. Do I need to put the if ($file != "" { before the very first line of the script (i.e. before if (isset($file)) {) and the closing } after the last line (i.e. after $msg=$tg_StatusMsg;
}
}
})? I tried several options, but I get the message "File Discrepancy Encountered. Upload Aborted". Is it a problem that my upload field is called "file" ? Any help is very much appreciated!
}
}
})? I tried several options, but I get the message "File Discrepancy Encountered. Upload Aborted". Is it a problem that my upload field is called "file" ? Any help is very much appreciated!