Gossamer Forum
Home : Products : DBMan : Customization :

Proposed change to image_upload mod :)

Quote Reply
Proposed change to image_upload mod :)
Hi all,

I have a dbman install which has been running fine for over a year now. My query concerns the image upload mod and deleting the associated image BUT not the record. On the odd occasion whe the client needs to REMOVE an image i have just been uploading a 1x1 transparent gif, yeh i know, lazy Blush However i would like to fix this.

I have an outline below and was hoping for a few pointers from you code junkies out there as to if it was a feasible plan or just complete madness Crazy I'm a little rusty having not touched DBman for a good while so be gentleWink I'm sure lots of you must have created a DELETE button?

1) Create a new field in database called 'DeleteImage'
Code:
'DeleteImage' => [ 10, 'alpha', 0, 3, 0, '', '']
Code:
# Checkbox fields. Field name => Checkbox value.
%db_checkbox_fields = (
'DeleteImage' => 'yes'
2) Add the extra field to all existing database records, ouch! Unimpressed

3) Add a checkbox called 'DeleteImage' in 'sub html_record_form' in html.pl
Code:
..... <TR class="bodycopy">
<TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><b>Delete Image:</b></TD>
<TD VALIGN="TOP" WIDTH="80%">&nbsp;|;

print &build_checkbox_field("DeleteImage",$rec{'DeleteImage'});

print qq|</TD></TR> .....
4) Insert this code **SOMEWHERE** in 'sub add_record' in 'db.cgi' so it gets executed when a record with an image is submitted. (this is the bit I can't really grasp where toput it)
Code:
if ($in{'DeleteImage'} eq "yes") {
unlink ("$file_upload_dir/$db_key.$ext");
}
5) Cross fingers and test Crazy

Thanks in advance for your time!
Quote Reply
Re: [philm] Proposed change to image_upload mod :) In reply to
Why don't you just provide a link at say the modify screen when the record is shown.

easier then adding a database field for it, no?

for example:

<a href="$db_script_url?photo=$ID&delete_image=true">delete the image</a>

Then in db.cgi do your unlinking in a sub that you call sub delete_image

and refer to it in sub main (db.cgi) by saying:

elsif ($in{'delete_image'}) { &delete_image; }
add the permissions stuff in this line.

Or does this make it even more complicated?

It worked well for me though...

Have fun,

Lex
Quote Reply
Re: [philm] Proposed change to image_upload mod :) In reply to
The multiple image upload mod has the option to delete an image. Perhaps comparing the subs for sub html_record_form and sub modify_record you could modify the single upload mod.

Please share your results if you get this going.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/