Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upload files to a directory

Status
Not open for further replies.

there

Programmer
Feb 4, 2002
15
CA
I have written a code to upload files to a directory but it only works if something is place in the upload files field. The problem arises when the upload file field is empty and you make changes to some of the other fields on the same form and it will not work. This is for adding and editing dynamic forms.

Where am I going wrong? How can I tell cgi that when the upload file field is empty, this is okay and go ahead and process the form in the database with the changes from other fields.

the code
-------
##--------
# uploadImage()
##--------
sub uploadImage
{

# need this transfer the right size of the file
$upload_logo = param('logo1');
$logo1 = lc(join '', split / /,(split/\\/, param("logo1"))[-1]);
# $upfile = lc(join '', split / /,(split/\\/, $logo1)[-1]);

$abs_file_to_create .= "/locato_on_web_server/";
$abs_file_to_create .= "$logo1";

open(NEW_FILE,">$abs_file_to_create") || die "Can't open $abs_file_to_create for output: $!";
binmode NEW_FILE;
while (read($upload_logo, $data, 8192))
{
print NEW_FILE $data;
}
close NEW_FILE;

} Thank you for your knowledge, wisdom and time!

There
 
just return from the function if there is no file to upload.
Code:
sub uploadImage
{

$upload_logo = param('logo1');
return unless $upload_logo; 
...

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top