Hello There, Guest!

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The most effective method to Resize And Add An Image To A Database
Little instructional exercise on the best way to re measure a picture with ColdFusion. 

To begin with we will make a shape where you can transfer the picture. 

Lets call it index.cfm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Untitled Document</title>
   <table border="0" cellpadding="0" cellspacing="1" width="500" align="center">
   <cfform action="picture_add.cfm" name="AddPic" method="post" enctype="multipart/form-data">
           <td align="right" class="Copy" valign="top">Photo:</td>
           <td align="left" class="Copy" valign="top">
               <cfinput type="file" name="PICTURE" required="no">
           <td align="left">
               <cfinput type="submit" name="Submit" value="Submit">

As should be obvious in our <CFFORM ></CFFORM >tags we call the page picture_add.cfm. 

So when you tap on submit catch the picture_add.cfm page will be called. 

Lets code the picture_add.cfm page.

<cfparam name="Error" default="">

<cfif Picture neq "">
           accept="image/jpeg, image/jpg, image/pjpeg"

           action = "info"
           source = "C:\ColdFusion9\wwwroot\test\images\tempupload\#serverfile#"
           structname = "Picturetest">
           <cfset Picturewidth =  #Picturetest.width#>
           <cfset Pictureheight =  #Picturetest.height#>
           <cfset PictureSmallwidth = 150>
           <cfset PictureSmallHeight = #Pictureheight# / #Picturewidth# * #PictureSmallwidth#>

       <cfimage action = "resize"
           height = "#Round(PictureSmallHeight)#"
           source = "#C:\ColdFusion9\wwwroot\test\images\tempupload\#serverfile#"
           destination = "C:\ColdFusion9\wwwroot\test\images\picturesmall\#serverfile#"
           overwrite = "yes">

   <cfcatch type="any">
       <cfset Error = "1">

<cfif ERROR eq 1>
   <script language="Javascript">
   alert ("Corrupt or invalid file type. .:Only jpg files accepted:.")
   <cfquery name="INSERTPRODUCT" datasource="yourdb">
       INSERT INTO yourname
   <script language="Javascript">
        alert ("Your picture has been uploaded.")
   <cflocation url="index.cfm">

Alright we have now coded the picture_add.cfm page 

Gives up through it well ordered. 

Initially we begin off with a parameter called "Blunder". 

Sick disclose to you later what this variable does. 

We at that point have a cfif articulation. 

This announcement tests the photo field in the index.cfm, it sees were there is a comment. 

The second articulation is there for blunder dealing with, an attempt proclamation on the off chance that anything isn't right with picture a mistake ought to be tossed. 

Our third field is the place the first picture will be transferred it will be sent to area picked by you. 

Your acknowledge writes disclose to you what document expansions to acknowledge. 

Nameconflict will instruct coldfusion if there are two pictures with the same. 

In the <cfimage> label the accompanying happens. 

The photos get re-sized and transferred to your particular registry. 

You should control the sizes of a picture since it will look irregular if the stature and width isn't correct. 

Next there is a catch proclamation to get all blunders. 

Keep in mind the variable that Error we pronounced right before all else this is the place we utilize it. 

We utilize another if explanation to test this esteem. 

On the off chance that our variable is equivalent to one we will utilize a bit of javascript code to tell the client that there is a mistake with the picture. 

We have a cfelse articulation this will execute if our blunder = ""(nothing). 

At that point we have an inquiry that will embed the photo into a database. 

I trust this appeared well and good and made a difference.
I didn’t realize that ColdFusion is still around. I remember that name from when I was studying Macromedia software.

[Image: giphy.gif] [Image: giphy.gif][Image: giphy.gif]
(04-20-2018, 12:57 AM)Shadow Fox Wrote: I didn’t realize that ColdFusion is still around. I remember that name from when I was studying Macromedia software.

[Image: giphy.gif] [Image: giphy.gif][Image: giphy.gif]

Its good to go old schoolSmile This brings back good memories from college.

Forum Jump:

Users browsing this thread: 1 Guest(s)