Gossamer Forum
Home : Products : DBMan : Customization :

Help with File Upload (upload graphics mod)

Quote Reply
Help with File Upload (upload graphics mod)
I've got the file upload mod installed and have it working. I use the single file upload mod and I don't require graphics to be uploaded.

Here's what I'd like to do...

######### Short Version ############
Use the "uid" instead of the "db_key" to keep track of the files (yes, I know, I know)... so that uploaded files will appear as "bob.1234566.txt" (instead of "1234.txt").

I looked through JPD's mod and only found two references to $db_key (for the parts I'm using - see her mod attached - note it has been stripped down to remove the options I'm not using).

I changed the $in{'$db_key'} to $in{'$db_uid'} but it didn't seem to work. The best I can tell the validate_upload sub is the only place where file names get "redone" for writing to the server.

Any help in pointing me in the "write" direction would be greatly appreciated. Tongue

########## Long Version ############
(this will help the above make more sense...)

1. I want my users to choose their upload file *before* they add a record and associate it with the uid (session) instead of a file name (since file name doesn't exist yet). This is optional. They don't have to upload a file if they don't want to. They will do this from the "home" page.

2. When they click "add new record" (from the "home page" to get to the add record form) the script will then run the validate_upload and stick a file on the server with uid.txt as the file name.

3. The user is now presented with the "Add Record" form where the following has happened:
(a) The script has opened and read the "text" file
(b) Parsed the data in the text file and populated the fields on the screen (and hidden) with the data from the uid.txt file
(c) And then has deleted (unlinked) the uid.txt file.

4. The user is now free to "add" the record or make changes before clicking add.

I'm basically giving my users a chance to upload data into a form from an "industry standard" type of output file instead of re-keying info that they already have in some type of software.

Last edited by:

Watts: Oct 10, 2005, 9:56 AM
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
Quote:
I changed the $in{'$db_key'} to $in{'$db_uid'}

Use $in{'uid'} or $db_uid.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
Many thanks, that works as intended.

(I tried several combinations, but apparently did not hit the correct one.)

Now on to phase #2 - wish me luck!
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
Best of luck!! :-)

If you have any problems, just holler.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
Okay, I'm hollering!

I need help with some of the logic...

(see attached for what I've hacked in so far - I've added all the other parts of the mod too, but I'm only posting the parts I'm tinkering with at the moment.)

1. I've added a "form" to the html_home sub so users can browse and select a file and then click a button that says "add record from file".

2. I've changed the submit part of the INPUT button to "validate_upload"

3. I've added the validate_upload line to the "main" sub in db.cgi to keep from getting an "unknown action" error

How does the "parse_form" sub fit in? Can I "call" it from validate_upload by adding &parse_form at the top of the validate_upload sub?

Also, I'm not sure what this line actually does:
if (($status eq "ok") && ($in{'Filename'})) { $status = &validate_upload; } #Validate Picture

It sets the value "status" to &validate_upload but not sure how that fits in.

Basically my users go to the "home" page, choose a file to upload, click add and are presented with a form in which parts (or all) of it are pre-filled based on the values in the file they uploaded. (I've got it working from "add_form", but I need to modify it to work from the "home" page).

If anyone is interested in the code for opening, reading and importing the data I'll be happy to share (it's only a few lines).

Last edited by:

Watts: Oct 11, 2005, 8:24 AM
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
You're on your way. Good job so far.

Quote:
How does the "parse_form" sub fit in?

That subroutine is called at the beginning of db.cgi, before it even gets to the "main" subroutine. You don't have to worry about calling it.

Quote:
Also, I'm not sure what this line actually does:
if (($status eq "ok") && ($in{'Filename'})) { $status = &validate_upload; } #Validate Picture

That line is usually added to sub add_record. The upload isn't validated until after the rest of the record is validated because there's no point in going through the whole upload process if the rest of the record isn't correct. It won't be necessary for your use.

The problem with what I see in your code is that after the file is validated, the script doesn't have anywhere to go. Normally the upload is validated from the add or modify routine and, if all is okay, the script goes back to the calling subroutine and finishes from there, including building a web page that tells the user what has happened. (Does that make any sense? :-) The only reason I know about this is that many, many times I have done exactly the same thing.

Off the top of my head, this is what I would do:

Change

elsif ($in{'validate_upload'}) { if ($per_add) { &validate_upload; } else { &html_unauth; } }

to

elsif ($in{'validate_upload'}) { if ($per_add) { &validate_upload_main; } else { &html_unauth; } }

Create a new subroutine:

sub validate_upload_main {
my $status;
$status = &validate_upload;
if ($status eq "ok") { &html_upload_success; }
else { &html_upload_failure($status); }
}

(Technically, you could just incorporate the code above into the existing subroutine, but it would take a number of edits, any one of which would be easy to miss. This is easier.)

In html.pl, create 2 new subroutines -- sub html_upload_success and sub html_upload_failure. I would use sub html_delete_success and sub html_delete_failure subroutines as examples. Just copy those two subroutines, change the names of them and change the wording to reflect uploading instead of deleting.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
I can't quite get it to work. By calling the validate_upload directly I get an Internal Server Error "The script did not produce any output."

If I copy the add_form/add_record subs and try to "trick" the db into "thinking" its adding a record (and thus upload the file) then the file gets written to the server but as 0 bytes.

I'm pretty sure it has something to do with the variable "Filename" which I've tried passing along as a hidden tag and even "hardcoding" it in db.cgi as
$filekey = "C:\CETemp\dos.pnt";
but no luck.

I'm gonna think this one over for a bit....
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
Quote:
By calling the validate_upload directly I get an Internal Server Error "The script did not produce any output."

Right. That's why you need to use the additional subroutines that I gave you in my previous post. They produce the output.

Quote:

If I copy the add_form/add_record subs and try to "trick" the db into "thinking" its adding a record (and thus upload the file) then the file gets written to the server but as 0 bytes.

You don't need to add a record or to go through the add record subroutine at all.

Did you implement the changes I suggested in my previous post? If so, what happened?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
I tried to get around the producing output bit by having the validate_upload sub print a bit of html thinking that would satisfy the server gods, but no luck. Then I tried having it call a sub &add_success; but that didn't seem to work either. I'll go back and try it again - you know how it gets after you've modified a script so many times you lose track of all of the little changes. I need to start over fresh.

In the meantime, I copied to whole sub into a separate cgi script and tried to get it to work as a stand alone script (see attached). I can get it to write the file to the server but it comes out "0" in size which tells me it's not really uploading anything.

I've noticed that I'm not getting the values from the input form and I'm not sure why. It works for me locally - I'm sure it's going to be something obvious.

You can see where I was hacking around trying to get variables to print in order to troubleshoot it by "hardcoding" variable values, etc.

Check it out and if you notice anything extremly stoopid let me know. Thanks.
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
I wouldn't know how to evaluate your stand-alone script. I'm sort of stuck within DBMan. And you'll need to change the name of the upload.htm file in order for me to read it. As it is, I just get a form and when I tried to use it, I ended up with a 404 error.

You really were headed in the right direction before and I think if you implemented the changes I suggested you would get closer to what you want. I'm really curious to find out if what I gave you worked.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
Many, many thanks... I'll give it the old "college try" again shortly. I think I'll hack it into a "fresh" dbman install and with everyone's help we can make it into an official mod.

(Currently I'm trying to integrate it into a heavily modified version and I'm not sure I'd be able to repeat what I did if anyone asked.)
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
<dances around office drawing stares from co-workers>

It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked! It worked!

</dances around office drawing stares from co-workers>

You're suggestions were "right on". I just needed to start over with a fresh script. I'll post what changes I made as soon as I have a change to play with it.

.
Quote Reply
Re: [Watts] Help with File Upload (upload graphics mod) In reply to
LOL!!!!

I do know the feeling of getting something to work that you've been trying for a while. It's a wonderful thing. I'm glad I could be a part of it.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Help with File Upload (upload graphics mod) In reply to
Here is the final hack that I've (We've) come up with. I'd be really curious to see if someone can replicate it.

The purpose is to take a text-delimited file generated by some popular software (kinda like clicking "File" --> "Export" in just about any kind of database program) and import it into the add record phase of dbman.

Currently it is set up to work with a text file in the following format (line number|value):

1|Eddie
2|Munster
3|1313 Mockingbird Ln
4|Hollyweird
5|CA
6|90210

... and so forth.

Since my db has over 500 fields and spans multiple pages you can see where it is beneficial for me to find a way for my users to import their info instead of re-typing a lot of data.

Anyway... FWIW here it is... If I notice any glaring errors I'll post corrections.