Gossamer Forum
Home : Products : DBMan : Customization :

Multiple file upload

Quote Reply
Multiple file upload
There is a conflict between mod 'validate records', 'multiple file upload' and 'preview records'.

After my installation of mod 'preview records' file upload stopped uploading files ... there is no error message but file upload will not write any file in the directory. And in preview all information about files is lost (maybe thats one of this 'bold' problems).

I read all posts about file upload problems (Win/'Bolding' etc.) but I have no idea how I can solve this problem. (I do not work on NT/Win and I have all permissions to chmod).

Are there some DBs with same problems? Is there someone who made a working combination of this mods?

Thanks - sab

Quote Reply
Re: Multiple file upload In reply to
I don't know if I can resolve the conflict between previewing and uploads. I'm thinking that I probably can't.

You will probably have to choose between using one mod and the other.

If you think any problem you have might be related to bolding, set $db_bold=0; in your .cfg file. That way there won't be any bolding. If the problem goes away, it was due to bolding. If it doesn't, it wasn't.



JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Multiple file upload In reply to
The solution for my problem is very simple. I just forgot to add some lines in the preview subs:

######################################################################
# file: db.cgi #
# sub preview_record #
######################################################################
# before
$status = &validate_record;

# add
if ($in{'file-to-upload-1'}) { $in{'Graphic'} = 'Yes'; }
else { $in{'Graphic'} = ''; }

# after #
# while ($status eq "duplicate key error" and $db_key_track) { #
# return "duplicate key error" if ($counter++ > 50); #
# $in{$db_key}++; #
# $status = &validate_record; #
# } #
# add

if (($status eq "ok") && ($in{'file-to-upload-1'})) { $status = &validate_upload; } #Validate Pictures

######################################################################
# file: html.pl #
# sub html_preview # #
# right at the beginning of the subroutines #
######################################################################

$form_upload_mod = 1;

######################################################################
# file: html.pl #
# sub html_preview #
# change #
# <form action="$db_script_url" method="POST"> #
# to #
######################################################################

<FORM ENCTYPE="multipart/form-data" action="$db_script_url" method="POST">

---
I think this will work. You will upload the files after you clicked on 'Preview Records'. That doesn't matter because its better to get all upload errors in your preview ...

sab, DBMan junior

Quote Reply
Re: Multiple file upload In reply to
Cool!! Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Multiple file upload In reply to
I forgot something else. If you like to enable 'delete' of files in preview form (modify) you have to add this lines:

# file: db.cgi
# sub preview_record
#
# after
# if ($in{'file-to-upload-1'}) { $in{'Graphic'} = 'Yes'; }
# else { $in{'Graphic'} = '';}
#
# add

foreach $key (keys %in) {
if ($in{$key} eq 'delete') {
unlink "$SAVE_DIRECTORY/$in{$db_key}/$key";
}
}


Hope that you can follow all this steps (read all posts to this entry before you change your code!).

sab

Quote Reply
Re: Multiple file upload In reply to
I'm setting up a news system with multiple file upload. Users can choose between .jpg/.gif/.rtf or .pdf
PDF and RTF files will appear as links at the bottom of the news page. Images at top of the html page.
Its working but there is one problem in this code. My statement in sub record works only if users have pdf or rtf in filename BEFORE the real file extension (.jpg etc).
How can I change this statement?

if (-e "$SAVE_DIRECTORY/$rec{$db_key}") {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$rec{$db_key}") or &cgierr("unable to open directory: $SAVE_DIRECTORY/$rec{$db_key}. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
next if ($file =~ /^rtf/); # Skip rtf type files.. does not work. RTF file extension is not skipped!
next if ($file =~ /^pdf/); # Skip pdf type files.. does not work - same as rtf

Sorry - this is an very simple (Perl) question.

SAB, Perl and DBMan Junior


Quote Reply
Re: Multiple file upload In reply to

next if ($file =~ /^rtf/); # Skip rtf type files.. does not work. RTF file extension is not skipped!
next if ($file =~ /^pdf/); # Skip pdf type files.. does not work - same as rtf


This doesn't work because the ^ means "starts with." The code below will probably work for you.


next if ($file =~ /\.rtf$/); # Skip rtf type files..
next if ($file =~ /\.pdf$/); # Skip pdf type files..


The $ means "ends with."

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Multiple file upload In reply to
Your postings are so fast I have no time to try other things!
You know there is one problem with my preview. If someone decide to post a news message and click on preview but is going off for a break ... the graphics will be uploaded while someone else is adding a record with same record number. All files will appear: Files of the breaking one and the new graphics of the none breaking one. How can I count records during preview? How can I change my count not only counting in .count?

Quote Reply
Re: Multiple file upload In reply to
I would suggest that you eliminate the preview.

Or you could add the following to sub get_defaults:

Code:

if ($db_key_track) {
open (ID, "<$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) { flock(ID, 1); }
$default{$db_key} = <ID> + 1; # Get next ID number
close ID;

open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock

}
Take out the added lines above from sub add_record.

You will probably have a lot of missing numbers in your counter field, but that really doesn't matter.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Multiple file upload In reply to
HI,

I am wondering if anyone knows how to
showing a pdf icon on the screen when the pdf file is uploaded.
and If you able to modify more ,
Could insert a clickable download link
which make possible also
download a pdf file direct from web?


thanks