Gossamer Forum
Home : Products : DBMan : Customization :

single + multi uploads...:)

Quote Reply
single + multi uploads...:)
Greetings, again!

I'm having a very peculiar problem with the upload mods. Let me explain:

1. I need to allow users to upload 2 images. One to be placed on top of the database (user's photograph) and 1 at the bottom (for one of the user's works).

2. The one at the top will be resized to a standar stamp size (like 100 px by 100 px) but the other will be shown as is, at the bottom of the page.

3. I tried using the multi upload mod, but when I do that I lose the control and placement of the first image.(user's photo).

4. What I am trying right now is a simple modification on the "single image upload" mod, thus simply duplicating the fields and renaming the folder for the second image. I am, however, having a real tough time in doing it. If someone is willing to give me a hand, I would most certainly appreciate it! The code is at the bottom of this message.

Thanks in advance,

Luis



------------------ default.cfg:

Filename => [16,'alpha',0,100,0,'',''],
Filename2 => [17,'alpha',0,100,0,'',''],

and

# File upload parameters
# --------------------------------------------------------
#
# File uploads -- if you want to be able to upload files, set this to 1
$db_upload = 1;

# Full path to directory for uploaded files -- NOT A URL!!!! No trailing slash please.
$SAVE_DIRECTORY = "/home/sites/site27/web/images/members";

# Full URL to directory for uploaded files. No trailing slash please.
$SAVE_DIRECTORY_URL = "http://www.paxbrasilis.com/images/members";

# Defines the number of bytes that can be uploaded. Files that exceed
# this limit will not be saved on the server. Set this to zero in order to
# disable size checking.
$MAXIMUM_UPLOAD = 100000;

# List of allowable file extensions. If the file does not have one of the extensions
# listed, it will not be saved to the server. The format for the setting is
# \.[extension]$ If you want to allow more than one extension, separate the options by
# a | character.
$ALLOWED_EXT = '\.gif$|\.jpg|$|\.jpeg';


# Full path to directory for uploaded files -- NOT A URL!!!! No trailing slash please.
$SAVE_DIRECTORYB = "/home/sites/site27/web/images/members/pics";

# Full URL to directory for uploaded files. No trailing slash please.
$SAVE_DIRECTORY_URLB = "http://www.paxbrasilis.com/images/members/pics";


# List of allowable file extensions. If the file does not have one of the extensions
# listed, it will not be saved to the server. The format for the setting is
# \.[extension]$ If you want to allow more than one extension, separate the options by
# a | character.
$ALLOWED_EXT = '\.gif$|\.jpg|$|\.jpeg';

at the bottom....


------------------ html.pl:

<TR>
<td align="Right" valign="top" width="120">

|; # to close off a previous print qq| statement
opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
print qq|<align=left><img src= "$SAVE_DIRECTORY_URL/$file" width=100 height=100
border=2></align>|;
$graphic_found=1;
}
}
print qq|


|;
unless ($graphic_found) {
print qq|<img src="../../images/members/default.gif">|;
}
print qq|


</td>


<TR>
<td align="Right" valign="top" width="120">

|;
# to close off a previous print qq| statement
opendir (GRAPHIC, "$SAVE_DIRECTORYB") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORYB. Reason: $!");

@files = readdir(GRAPHIC);

closedir (GRAPHIC);

$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
print qq|<align=left><img src= "$SAVE_DIRECTORY_URLB/$file"></align>|;
$graphic_found=1;
}
}

print qq|


</td>


Quote Reply
Re: single + multi uploads...:) In reply to
You can rename the file after it's uploaded.

Here's what I would do.

In your .cfg file, set up an array with the names that you want to give the pics:

$newfile[1] = "photo";
$newfile[2] = "works";


Notice that you need to start with number 1 and that you must have an entry in the array for as many files as you allow to be uploaded.

In db.cgi, sub validate_upload, before

if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$newdirname\/$filename")) {

add

$filename = $newfile[int($Number)] . substr($filename,index($filename,"."));

Then all of the files will have the same name (except for the extensions) and you can print them out as you want to.

I haven't tried in action, but I know the line above works.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: single + multi uploads...:) In reply to
Hey, JP....thanks for your help! I still was not successful, but I think there may be a better solution outside the DB man realm...(I'm thinking of providing the members free web space...we'll see).

Anyway, thanks for the time and the attention and hope your back feels bettter! (I didn't know you were sick! Well..get better SOON!! This forum would fall apart without you :)))

Best wishes !

Lubatico

Quote Reply
Re: single + multi uploads...:) In reply to
HI, It works but if I modify_form by upload a new file ,How it replaces the first old uploaded file with the new?????


Please Excuse me for my poor knoledge of PERL
Regards,
Act.
Quote Reply
Re: single + multi uploads...:) In reply to
Act, in order to stop the modify form from overwriting your existing files is to:

1) make sure you have however number of upload files you want named in your cfg file.

ie $newfile[1] = "something1";
$newfile[2] = "something2";
$newfile[3] = "something3";
$newfile[4] = "something4";

2) Then in your modify form in your html.pl you will have to add a subroutine that will block out the specific upload fields based on the number of files already uploaded.

ie something to the effect of:

1) Check number of files currently uploaded for this record
2) If say, File 1 is uploaded, then
don't show File1 upload Field
If File 2 is uploaded then
dont show File2 upload Field

Of course, this method will not allow them to modify the currently uploaded files

Trev


Quote Reply
Re: single + multi uploads...:) In reply to
HI, TrevR
Thank fro your help :-)
Could you please code me , I wornder and dont know what to add more,
I think the JPDeni modify mod already has what you told me,is't it?But why I need to add more. May be I am worng that what I have to asking you for help...
Aprriciated your help!


Please Excuse me for my poor knoledge of PERL
Regards,
Act.
Quote Reply
Re: single + multi uploads...:) In reply to
Because JPDeni's Mod is basically for EITHER single or multiple file uploads, but not a combination of both.

Regards,

Eliot Lee
Quote Reply
Re: single + multi uploads...:) In reply to
HI, I think I am wrong so I deleted a post of my out from here.
After thinking of how if we try to make code to tell script know which of
$newfile[1] = "me1";
$newfile[2] = "me2";
$newfile[3] = "me3";
$newfile[4] = "me4";
$newfile[5] = "me5";
are already uploaded as TrevZ told,why don't code the $newfile to 1,2,3,4,5.....andn so on,due to prevent the replaceing of the same files name,right?
..... could any one reply me? or if you think the better way to solve this solution.,please guide me,also it would be great if give me the code :)

Any help 'd be GREAT appriciated.
Regards,
Act.
Quote Reply
Re: single + multi uploads...:) In reply to
Is it possible?I really need help.

Love you all,and thank for all help here ,this is a greatest forum.
Act.
Quote Reply
Re: [TrevR] single + multi uploads...:) In reply to
In Reply To:
Act, in order to stop the modify form from overwriting your existing files is to:

1) make sure you have however number of upload files you want named in your cfg file.

ie $newfile[1] = "something1";
$newfile[2] = "something2";
$newfile[3] = "something3";
$newfile[4] = "something4";

2) Then in your modify form in your html.pl you will have to add a subroutine that will block out the specific upload fields based on the number of files already uploaded.

ie something to the effect of:

1) Check number of files currently uploaded for this record
2) If say, File 1 is uploaded, then
don't show File1 upload Field
If File 2 is uploaded then
dont show File2 upload Field

Of course, this method will not allow them to modify the currently uploaded files

Trev
Any one how to?

1) Check number of files currently uploaded for this record
2) If say, File 1 is uploaded, then
don't show File1 upload Field
If File 2 is uploaded then
dont show File2 upload Field

Love you all,and thank for all help here ,this is a greatest forum.
Act.
Quote Reply
Re: [JPDeni] single + multi uploads...:) In reply to
i have this working great for uploading. but i can't figure out how to print the two separate files in different places. for example, i want the thumbnail in the short display and the other image in the long display. the problem is, i don't know what the extension is -- either could be gif or jpg. how do i match the left side of the $file to the array names and then put the extension back on? or there is probably an easier way? thanks!


EDIT:

This is what i did and it seems to work:

next if ($file =~ /^$newfile[1]/); # Skip first file in array..

then i changed [1] to [2] in the other part. seems to work ok, but i'm open to suggestions if someone has a more elegant solution.

Last edited by:

delicia: Nov 30, 2003, 12:57 PM
Quote Reply
Re: [delicia] single + multi uploads...:) In reply to
A solution is available in the FAQ noted below in the section under "Images" in a thread called "Multiple Image Upload (graphic files at different positions)"

This should provide what you need.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] single + multi uploads...:) In reply to
i had seen that post; if you check your logs you'll see i've been a frequent visitor!Smile but i couldn't figure out how to adapt it to a regular image and a thumbnail. however, the code i posted above works so i'll stick with it.

in case anyone else is interested, i also figured out a way to allow the image and thumbnail to be uploaded at separate times (modifying the original record). again, it isn't elegant, but it works:

Code:
if ($form_upload_mod) {
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);
my $image;
my $thumb;
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
if ($file =~ /^$newfile[1]/) { $image_found = 1; }
if ($file =~ /^$newfile[2]/) { $thumb_found = 1; }
++$num_files;
@stats = stat "$SAVE_DIRECTORY/$rec{$db_key}/$file";
$prev_bytes +=$stats[7];
}
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
print qq|<tr><td>Delete file
<input type="checkbox" name="$file" value="delete"></td>
<td><img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$file"></td></tr>|;
}
}
if (!$image_found) {
# print qq|<tr><td colspan=2>You currently have $num_files files associated with this record, for a
# total of $prev_bytes bytes. You must delete these files before uploading new files for this records.</td></tr>|;
print qq|
<TR><TD>$newfile[int(1)]:</TD>
<TD><INPUT TYPE="FILE" NAME="file-to-upload-1" SIZE="50"></TD></TR>|;
}
if (!$thumb_found) {
# print qq|<tr><td colspan=2>You currently have $num_files files associated with this record, for a
# total of $prev_bytes bytes. You must delete these files before uploading new files for this records.</td></tr>|;
print qq|
<TR><TD>$newfile[int(2)]:</TD>
<TD><INPUT TYPE="FILE" NAME="file-to-upload-2" SIZE="50"></TD></TR>|;
}
#else {
# $new_files=$MAXIMUM_FILES - $num_files;
# $new_bytes=$MAXIMUM_UPLOAD - $prev_bytes;
# print qq|<tr><td colspan=2>You currently have $num_files files associated with this record, for a
# total of $prev_bytes bytes. You may upload up to $new_files additional files, with a total byte
# size of $new_bytes bytes.</td></tr>|;
# for ($u=1;$u<=$new_files ;++$u) {
# print qq|
# <TR><TD>$newfile[int($u)]:</TD>
# <TD><INPUT TYPE="FILE" NAME="file-to-upload-$u" SIZE="50"></TD></TR>|;
# }
#}
}