I want to create a custom function for deleting photos from my app (as
well as many other udf's).  When someone deletes a photo, several
processes need to take place. The related db records need to be
deleted, the file needs to be deleted, etc.

I'm reading the howto at http://coldblue.net/?p=176

To delete a photo, I need a photo_id. Once I have this, I can pull the
photo info, make sure the member has ownership, and run the various
scripts required to cleanly delete the photo.

I'd like the function to be as simple as #deletePhoto(url.photo_id)#

This way I could have a url such as company.com/
deletePhoto.cfm&photo_id=3454354

DeletePhoto.cfm would simply contain

---------------
<cfoutput>
#deletePhoto(url.photo_id)#
</cfoutput>

--------------------

And in a folder called functions (the folder would just be a global
dir for my functions I write) I'd have a document called
f_deletephoto.cfm containing something like the following:

-----------------------------------
<cffunction name="deletePhoto">
        <cfargument name="photo_id" type="numeric" required="true" />
        <cfif StructKeyExists(session.myid)>
                <cfquery name="delete_photo" datasource="photos">
                        DELETE
                        FROM tbl_member_photos
                        WHERE   (member_id = <cfqueryparam 
value="#session.myid#">) and
                                (photo_id = <cfqueryparam 
value="#select_photo.photo_file#">)
                </cfquery>
        </cfif>
        <cfif recordcount.delete_photo eq 1>
                <b>SUCCESS!</B>
        <cfelse>
                <b>FAIL!</B>
        </cfif>
</cffunction>
-----------------------------------

Now.. my question is, how do I define this function for global use? Is
there a folder I place my functions in that gets called when the app
starts? Do I have to register them in an OpenBD config somewhere?
Include it in my application.cfm?

I'm not sure how to configure it so I can call this udf at anytime
without having to load the function anytime I use it. Also, does my
function script look valid?

-- 
online documentation: http://openbd.org/manual/
   google+ hints/tips: https://plus.google.com/115990347459711259462
     http://groups.google.com/group/openbd?hl=en

Reply via email to