Gossamer Forum
Home : Products : DBMan : Customization :

uploading file hack

Quote Reply
uploading file hack
believe it or not, i've accomplished a lot without having to ask questions! but here's another one.

i'm trying to make all the hacks work with autogenerate. i have file upload, instant modify/delete, and some others working fine. i want to tweak the file upload a little. instead of testing by the fieldname = Filename, i would prefer to change the field type to file (instead of alpha) and use that field (i think it's $db_sort). that way i could have a more descriptive fieldname for the file without having to use a custom html or modifying for each application/database.

db.cgi has following in sub add_record:

Code:


my ($output, $status, $counter);

# Set the userid to the logged in user.

($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);



# First we validate the record to make sure the addition is ok.

$status = &validate_record;

# We keep checking for the next available key, or until we've tried 50 times

# after which we give up.

while ($status eq "duplicate key error" and $db_key_track) {

return "duplicate key error" if ($counter++ > 50);

$in{$db_key}++;

$status = &validate_record;

}

###

if (($status eq "ok") && ($in{'Filename'})) { $status = &validate_upload; } #Validate Picture

#####



it's the last line above $in{'Filename'} that i want to change the test to ?? eq 'File'. i can't figure out where to start. it seems that if Filename is available here, the data type should also be available.

then in modify_record:

Code:


$db_not_null{'Filename'} = 0;



i need to do something similar here - help!

Quote Reply
Re: [delicia] uploading file hack In reply to
I think you will come to find out that adding mods while using autogenerate is going to end up causing you problems. Many mods will not work when you use the autogenerate.

I dont' see how you can use the upload mod with autogenerate as you would then not be able to add the coding necessary in the add_record and display sub(s).

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] uploading file hack In reply to
i added the code in the build_html_record sections of db.cgi to upload file. it works fine!
Quote Reply
Re: [delicia] uploading file hack In reply to
finally have time to work on this again. what i have working is the file upload. unfortunately i still can't figure out how to determine the data type. in sub query:

if (($db_sort{$column} eq 'date')

so i know it's sometimes possible to see the value of the data type column. is it possible to determine the type if you know the column name (in my example 'Filename')?

Quote Reply
Re: [delicia] uploading file hack In reply to
Quote:
is it possible to determine the type if you
know the column name (in my example 'Filename')?

Take a look at sub validate_record in db.cgi as it uses the information you want.

I think it is what you want.
Quote Reply
Re: [delicia] uploading file hack In reply to
Well, you can put "file" in your .cfg-file for the field "Filename", into the field type position, where other fields have "alpha", "date", and so on, sure.

But I'm not sure what you want to accomplish. How would this get you "more descriptive file names"?

Sure, you can test whether $db_sort{Filename} = "file", but you know that anyway because you defined it this way, so why bother? Or do you want to do something with upload fields in cases where you don't know the fieldname? Like:

foreach my $col (@db_cols) { if ($db_sort{$col}) eq "file") { print "bingo! $col is a file upload field!\n";}}

Just asking ...
kellner
Quote Reply
Re: [kellner] uploading file hack In reply to
you got it -- i want to cover cases in which i don't know the field name and i don't want to be forced to use "filename" as the field name.
Quote Reply
Re: [delicia] uploading file hack In reply to
Ah, so it's not "more descriptive file names", but more descriptive names of the file upload fields! Now I get it. Well then, the foreach-loop I posted above is the right (well, one right) way to go.
kellner