AndyJarrett Code. Develop. Manage.

Insert images into MySQL (or any DB really)

Never really had a need to do this, and as i type this i still cant think of a reason why to do this (im open to ideas). Either way it got asked on alt.comp.lang.coldfusion so i thought i'd find the solution and share it for my reference and anyone elses:
   <!--- The form to upload the image --->
   <form action="#cgi.SCRIPT_NAME#" method="post" enctype="multipart/form-data">
      <input type="File" name="imgFile"/>
      <input type="Submit" value="submit"/>
   <cfif isDefined("form.imgFile")>
      <!--- UPload the image to the server --->

      <!--- Read the file as binary to be inserted into the DB --->

      <!--- Conver the binary to toBase64, this converts the binary to printable form --->
      <cfquery datasource="test" name="upldBinImg">
         INSERT INTO tablename
         SET q = '#toBase64(binaryImgFile)#'