Gossamer Forum
Home : Products : DBMan : Customization :

graphic delete problem with multi-upload

Quote Reply
graphic delete problem with multi-upload
Hello everyone,

I'm having a problem with deleting graphics and their associated subdirectory when I use multi-upload to upload 2 graphics. I have it working fine on 3 databases when I only upload 1 graphic so I'm stymied.

Here's what I have in dg.cgi in the delete_records routine to delete the graphics:

if ($delete_list{$data[$db_key_pos]}) { # if this id is one we want to delete
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.
if ($db_upload) {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$data[$db_key_pos]") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY/$data[$db_key_pos]. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
foreach $file (@files) {
unlink ("$SAVE_DIRECTORY/$data[$db_key_pos]/$file");
}
rmdir "$SAVE_DIRECTORY/$data[$db_key_pos]";
}
}
else { $output .= $line . "\n"; }
}


I know it is recognizing the directory name because I renamed it and got the error message. As I understand this coding, it is simply opening the directory, reading the files to an array (or something) called @files, then putting @files into a variable called $files. Then it simply deletes the files in the directory and then removes the directory.

Here's what I have in the .pl file record_edit that pertains to adding or modifying records with graphics:

if ($form_upload_add) {
print qq|<tr><td colspan=3><center><$font>You may upload a Student picture and a Speaker picture.</center></font>

<TR><TD colspan=3><center><$font>Browse your computer to upload a <b><u>Student</u></b> picture!

Valid file formats are .jpg or .gif
<INPUT TYPE="FILE" NAME="file-to-upload-1" SIZE="48"></TD></TR></font></center>

<TR><TD colspan=3><center><$font>Browse your computer to upload a <b><u>Speaker</u></b> picture!

Valid file formats are .jpg or .gif
<INPUT TYPE="FILE" NAME="file-to-upload-2" SIZE="48"></TD></TR></font></center>|;
}

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);
@photo = qw();
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
push(@photo, $file);
}
}

if (($photo[0]) or ($photo[1])) {
print qq|<tr><td colspan=3 ><$font>Delete Speaker Picture?
<input type="checkbox" name="$photo[0]" value="delete"> (Delete the old file while uploading a new file)</td>
</tr></font>
<tr><td colspan=3 ><$font>Delete Student Picture?
<input type="checkbox" name="$photo[1]" value="delete"> (Delete the old file while uploading a new file)</td>
</tr></font>|;
}
{
print qq|<tr><td colspan=3><center><$font>You may upload a new Student picture or Speaker picture.</center></font>

<TR><TD colspan=3><center><$font>Browse your computer to upload a <u><b>Student</b></u> picture!

Valid file formats are .jpg or .gif
<INPUT TYPE="FILE" NAME="file-to-upload-1" SIZE="44"></TD></TR></font></center>

<TR><TD colspan=3><center><$font>Browse your computer to upload a <u><b>Speaker</b></u> picture!

Valid file formats are .jpg or .gif
<INPUT TYPE="FILE" NAME="file-to-upload-2" SIZE="44"></TD></TR></font></center>|;
}
}

print qq|



Here's how I display the graphics in record_long:

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);
@photo = qw();
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
push(@photo, $file);
}
}
if ($photo[0]=~ /$ALLOWED_EXT/)

{
print qq|<center><img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[0]" height="192" width="128"></center>|;
}

else {
print qq|<center>No Student Picture Uploaded</center>|;
}

and the other graphic:

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);
@photo = qw();
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
push(@photo, $file);
}
}

if ($photo[1]=~ /$ALLOWED_EXT/)

{
print qq|<center><img src= "$SAVE_DIRECTORY_URL/$rec{$db_key}/$photo[1]" height="192" width="128"></center>|;
}

else {
print qq|<center>No Speaker Picture Uploaded</center>|;
}



Can anybody see any obvious problems? Like I say, I have this mod working well with only a single graphic uploaded so I don't understand the difference.

Thanks,
Chris Whatley