Solved

upload-resize  multiple image

Posted on 2008-06-16
34
441 Views
Last Modified: 2013-12-24
Hello experts.
I have a working code for uploading and resizing one image.
Now i want these to work for more than one image and
get the values of the uploaded images and thumbs into a DB.
The DB is Like:
Photo
Art_id  int
foto_1 varchar
foto_2 varchar
foto_1_thumb varchar
foto_2_thumb  varchar.
Below is the code for one image:
<!---

   Create folder structure or change to fit your needs

   Expects images to be uploaded to images and thumbnails go in thumbs

--->
 
 

<!--- set the full path to the images folder --->

<cfset mediapath = expandpath('./image')>
 

<!--- set the desired image height ---->

<cfset thumbsize = 75>
 

<!--- set the desired image width --->

<cfset imagesize = 320>
 
 

<cfif structKeyExists(form,"foto1") and len(form.foto1)>

   <cffile action="upload"

   filefield="foto1"

   destination="#MediaPath#"

   nameconflict="makeunique">

   

   <!--- read the image ---->

   <cfimage name="uploadedImage"

   source="#MediaPath#/#file.serverFile#" >
 

   <!--- figure out which way to scale the image --->

   <cfif uploadedImage.width gt uploadedImage.height>

         <cfset thmb_percentage = (thumbsize / uploadedImage.width)>

         <cfset percentage = (imagesize / uploadedImage.width)>

      <cfelse>

         <cfset thmb_percentage = (thumbsize / uploadedImage.height)>

         <cfset percentage = (imagesize / uploadedImage.height)>

  </cfif>

   

   <!--- calculate the new thumbnail and image height/width --->

   <cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>

   <cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>
 

   <cfset newWidth = round(uploadedImage.width * percentage)>

   <cfset newHeight = round(uploadedImage.height * percentage)>
 

   <!--- see if we need to resize the image, maybe it is already smaller than our desired size --->

   <cfif uploadedImage.width gt imagesize>

         <cfimage action="resize"

       height="#newHeight#"

       width="#newWidth#"

       source="#uploadedImage#"

      destination="#MediaPath#/#file.serverFile#"

       overwrite="true"/>

  </cfif>
 

    <!--- create a thumbnail for the image --->

  <cfimage action="resize"

    height="#thumbHeight#"

    width="#thumbWidth#"

    source="#uploadedImage#"

    destination="#MediaPath#/thumb/#file.serverFile#"

    overwrite="true"/>

   

   <cfoutput>

     <img src="image/thumb/#file.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>
 

      Original Image: #uploadedImage.width#x#uploadedImage.height#<br>

      Resized Image: #newWidth#x#newHeight#<br>

    Thumbnail: #thumbWidth#x#thumbHeight#<br><br>

      <a href="image/#file.serverFile#">See Image</a><br>

      

   </cfoutput>

</cfif>   
 

<form action="test1.cfm" method="post" enctype="multipart/form-data">

   <label for="fileUpload">Choose Image: </label>

   <input  type="file" name="foto1"  id="foto1"  />

   <input type="submit" value="Upload Image">

</form>

Open in new window

0
Comment
Question by:Panos
  • 18
  • 14
  • 2
34 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 21802223
all you need do is add multiple input type=file on form page then loop through them on action page
<input  type="file" name="foto1"  id="foto1"  />
<input  type="file" name="foto2"  id="foto2"  />
you do need to let the action page know how many file fields you have
you can hard code it or figure out some code
for this ex we'll just hard code it
<cfset uploadNum=2>
<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->
<cfif StructKeyExists(form,"foto" & ZZ) and len(trim(Form["foto" & ZZ]))><!--- 2 --->
      <CFFILE ACTION="UPLOAD"
            FILEFIELD="foto#ZZ#"
            DESTINATION="#mediapath#"
            NAMECONFLICT="makeunique">
      so just do all your stuff here at this point within this loop
</cfif><!--- 2 --->
</cfloop><!--- 1 --->
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 21802872
fyi (no points pls as it doesn't address the question)...there's a bug in cfimage in 8.01 related to not releasing file locks properly.

description and hotfix - http://www.adobe.com/go/kb403411

I spent 3 hours dealing with this..so you don't have to.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21802921
SidFishes : fighting evil - so you don't have to ...

thanks Sid - I was unaware of this
0
 
LVL 2

Author Comment

by:Panos
ID: 21803005
Hello dgrafx
I have tested your code and i have the following problems.
I get here : <cfoutput>
     <img src="image/thumb/#file.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>
 
      Original Image: #uploadedImage.width#x#uploadedImage.height#<br>
      Resized Image: #newWidth#x#newHeight#<br>
    Thumbnail: #thumbWidth#x#thumbHeight#<br><br>
      <a href="image/#file.serverFile#">See Image</a><br>
     
   </cfoutput>
the first picture twice.
2:Using this code i can't get the values in the DB.
3:Is it better to get all the imag in 1 column in DB or like i wanted in separate.
I 'm asking because i want to let one user to upload max 8 img.Then i want to display them in specific imageholders.Also  update or delete the images he wants to.
0
 
LVL 2

Author Comment

by:Panos
ID: 21803065
Hi sidfishes too.
I don't understand what you are talking about but I have installed long ago the hotfix.
0
 
LVL 2

Author Comment

by:Panos
ID: 21803086
I have forgotten to say that i'm using SQL server
0
 
LVL 36

Expert Comment

by:SidFishes
ID: 21803141
(if you have that hotfix installed just ignore my comments)
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21803201
ok - so you need to do all your stuff WITHIN the loop as i said

cfloop ....
upload file
insert to db
and whatever else on each loop
/cfloop

then to display you can do a couple things
you could query the db for this last transaction and display what was done
you'd need to insert a transaction ID so you can get the correct records
anyway ... that's another story
or you can use cfsavecontent
lets give an ex using cfsavecontent
<cfset content1="">
cfloop ...
upload file
insert to db & whatever else
<cfoutput>
<cfsavecontent variable="content2">
#content1#
Original Image: #uploadedImage.width#x#uploadedImage.height#<br>
Resized Image: #newWidth#x#newHeight#<br>
Thumbnail: #thumbWidth#x#thumbHeight#<br><br>
<a href="image/#cffile.serverFile#">See Image</a><br><br>
</cfsavecontent>
</cfoutput>
/loop

<cfoutput>#content2#</cfoutput>

NOTE - it's CFFile.Serverfile - File.Serverfile is deprecated
0
 
LVL 2

Author Comment

by:Panos
ID: 21803409
Hi dgrafix.
Sorry that i'm asking again and again but i'm a little confused.I have tested many codes from my bookes and in the net but i cannot find exactly what i want.Some do upload but not put the values in the DB , others are uploading only one picture in Db with values like :....
<cfset image64=toBase64(binimage)>
<cfquery DATASOURCE="dsn">
UPDATE Userdaten
SET bilddaten='#image64#',..........
and others don't resize.
Can you please wright the code with all the stuff if it is not difficult for you?
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21803454
you want to put the image in binary form in the database?
are you sure?
why not just a link to where it is saved?

let me know ...
0
 
LVL 2

Author Comment

by:Panos
ID: 21803676
I don't know what is the best way .I'm trying to describe you what i want to do so that you could better understand.
Look .
First upload the images and create the thumbs.Than on a detail page get the images with a query  in a table  with the thumbs and one big image in the center.On thumbs rollover i get the bigimages from each thumb  i the center.I have the scripts for the second function.
0
 
LVL 2

Author Comment

by:Panos
ID: 21803699
And something else.
I want to have them as a link.I did write the binary... to show you why  i'm confused.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21803889
ok - forget the binary stuff
this is just simple image upload and display
just do it as i showed you and insert to db
when customer is viewing their images (or whatever is happening) you have a query thats outputting their images

good luck ...
0
 
LVL 2

Author Comment

by:Panos
ID: 21805579
Hi dgrafx.
Ok .
Look please the code and help me with the insert.......value....
<!---

   Create folder structure or change to fit your needs

   Expects images to be uploaded to images and thumbnails go in thumbs

--->

 

 

<!--- set the full path to the images folder --->

<cfset mediapath = expandpath('./images')>

 

<!--- set the desired image height ---->

<cfset thumbsize = 75>

 

<!--- set the desired image width --->

<cfset imagesize = 320>

 <cfset uploadNum=2>

<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->

 

<cfif StructKeyExists(form,"foto" & ZZ) and len(trim(Form["foto" & ZZ]))><!--- 2 --->

    <CFFILE ACTION="UPLOAD"

            FILEFIELD="foto#ZZ#"

            DESTINATION="#mediapath#"

            NAMECONFLICT="makeunique">

   <!--- read the image ---->

   <cfimage name="uploadedImage"

   source="#MediaPath#/#cffile.serverFile#" >

 

   <!--- figure out which way to scale the image --->

   <cfif uploadedImage.width gt uploadedImage.height>

         <cfset thmb_percentage = (thumbsize / uploadedImage.width)>

         <cfset percentage = (imagesize / uploadedImage.width)>

      <cfelse>

         <cfset thmb_percentage = (thumbsize / uploadedImage.height)>

         <cfset percentage = (imagesize / uploadedImage.height)>

  </cfif>

   

   <!--- calculate the new thumbnail and image height/width --->

   <cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>

   <cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>

 

   <cfset newWidth = round(uploadedImage.width * percentage)>

   <cfset newHeight = round(uploadedImage.height * percentage)>

 

   <!--- see if we need to resize the image, maybe it is already smaller than our desired size --->

   <cfif uploadedImage.width gt imagesize>

       <cfimage action="resize"

       height="#newHeight#"

       width="#newWidth#"

       source="#uploadedImage#"

       destination="#MediaPath#/#cffile.serverFile#"

       overwrite="true"/>

  </cfif>

 

    <!--- create a thumbnail for the image --->

  <cfimage action="resize"

    height="#thumbHeight#"

    width="#thumbWidth#"

    source="#uploadedImage#"

    destination="#MediaPath#/thumb/#file.serverFile#"

    overwrite="true"/>

   

   <cfoutput>

     <img src="images/thumb/#cffile.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>

 

      Original Image: #uploadedImage.width#x#uploadedImage.height#<br>

      Resized Image: #newWidth#x#newHeight#<br>

    Thumbnail: #thumbWidth#x#thumbHeight#<br><br>

      <a href="images/#cffile.serverFile#">See Image</a><br>

      

   </cfoutput>

</cfif> 

</cfloop> 

<cfquery  name="qFotos" datasource="#dsn#" >

   insert into photo (foto_1,foto_2,thumb_1,thumb_2)

    values.....

    

    </cfquery>  

 

<form action="test1.cfm" method="post" enctype="multipart/form-data">

   <label for="fileUpload">Choose Image: </label>

   <input  type="file" name="foto1"  id="foto1"  />

   <input  type="file" name="foto2"  id="foto2"  />

   

   <input type="submit" value="Upload Image">

</form>

Open in new window

0
 
LVL 2

Author Comment

by:Panos
ID: 21810284
Hi dgrafx.
One thing more.i noticed that thegenerated  image name and the thumname are the same but of course in different folders.That means that i don't need the thumb1 and thumb2 in my DB.The output for the thumbs must be <cfoutput>thumbs/#qFoto.foto1#</cfoutput> and <cfoutput>thumbs/#qFoto.foto2#</cfoutput>.
As you said the query must be in the cfif(it is wrong on my last  code).The only thing now is to specify the Insert values!
<!---

   Create folder structure or change to fit your needs

   Expects images to be uploaded to images and thumbnails go in thumbs

--->

 

 

<!--- set the full path to the images folder --->

<cfset mediapath = expandpath('./images')>

 

<!--- set the desired image height ---->

<cfset thumbsize = 75>

 

<!--- set the desired image width --->

<cfset imagesize = 320>

 <cfset uploadNum=2>

<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->

 

<cfif StructKeyExists(form,"foto" & ZZ) and len(trim(Form["foto" & ZZ]))><!--- 2 --->

    <CFFILE ACTION="UPLOAD"

            FILEFIELD="foto#ZZ#"

            DESTINATION="#mediapath#"

            NAMECONFLICT="makeunique">

            

   <!--- read the image ---->

   <cfimage name="uploadedImage"

   source="#MediaPath#/#cffile.serverFile#" >

 

   <!--- figure out which way to scale the image --->

   <cfif uploadedImage.width gt uploadedImage.height>

         <cfset thmb_percentage = (thumbsize / uploadedImage.width)>

         <cfset percentage = (imagesize / uploadedImage.width)>

      <cfelse>

         <cfset thmb_percentage = (thumbsize / uploadedImage.height)>

         <cfset percentage = (imagesize / uploadedImage.height)>

  </cfif>

   

   <!--- calculate the new thumbnail and image height/width --->

   <cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>

   <cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>

 

   <cfset newWidth = round(uploadedImage.width * percentage)>

   <cfset newHeight = round(uploadedImage.height * percentage)>

 

   <!--- see if we need to resize the image, maybe it is already smaller than our desired size --->

   <cfif uploadedImage.width gt imagesize>

       <cfimage action="resize"

       height="#newHeight#"

       width="#newWidth#"

       source="#uploadedImage#"

       destination="#MediaPath#/#cffile.serverFile#"

       overwrite="true"/>

  </cfif>

 

    <!--- create a thumbnail for the image --->

  <cfimage action="resize"

    height="#thumbHeight#"

    width="#thumbWidth#"

    source="#uploadedImage#"

    destination="#MediaPath#/thumb/#cffile.serverFile#"

    overwrite="true"/>

   

   <cfoutput>

     <img src="images/thumb/#cffile.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>

 <img src="images/#cffile.serverFile#" height="#newHeight#" width="#newWidth#" align="left" hspace="10"></br>

      Original Image: #uploadedImage.width#x#uploadedImage.height#<br>

      Resized Image: #newWidth#x#newHeight#<br>

    Thumbnail: #thumbWidth#x#thumbHeight#<br><br>

      <a href="images/#cffile.serverFile#">See Image</a><br>

      

   </cfoutput>

   <cfquery  name="qFotos" datasource="carfree24" >

   insert into photo (foto1,foto2)

    values ........

    

  </cfquery>

 

</cfif> 

</cfloop> 
 

<form action="test1.cfm" method="post" enctype="multipart/form-data">

   <label for="fileUpload">Choose Image: </label>

   <input  type="file" name="foto1"  id="foto1"  />

   <input  type="file" name="foto2"  id="foto2"  />

   

   <input type="submit" value="Upload Image">

</form>

Open in new window

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21812011
ok - i'm back ...
what do you want to insert?
name of foto? you said up to 8?
the user it belongs to?
can you post a list of what all you want to insert please?
0
 
LVL 2

Author Comment

by:Panos
ID: 21812120
Hi dgrafx.
I'm back too.
i have a table with many columns but in this case that what i want is to get the 8 fotos in there.
The names are foto1,foto2,foto3.........foto8.
I need thumbs as in my example(in a folder images/thumbs).I think the thumbs don't need to be in the DB because the generated name of the resized image and the thumb are the same(only the folder is different).
I don't no the problems if i will try to validate each foto.(size and file)But this could be a second question and you could help me there again.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 25

Expert Comment

by:dgrafx
ID: 21812244
ok
so do this

<cfset fotos="">
<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->
then your other code ...
right after your cffile tag do
<cfset fotos=ListAppend(fotos,cffile.serverfile)>
....
</cfloop><!--- 1 --->
then outside your loop:
<cfquery ...>
insert into your table
(UserID,fotos)
values
(#UserID#,'#fotos#')
</cfquery>

then on page where user wants to look at images
<cfquery ... name="getFotos">
select fotos
from table
where userID = #userid#
</cfquery>

<cfset thumbDir="D:\web\site1\custimg\thumbs\">
<cfset thumbPath="/custimg/thumbs/">
<cfset imageDir="D:\web\site1\custimg\image\">
<cfset imagePath="/custimg/image/">
<cfoutput query="getFotos">
<cfloop list="#getFotos.fotos#" index="ii">
<cfif fileExists(thumbDir & ii)>
<img src="#thumbPath##ii#">
</cfif>
<cfif fileExists(thumbDir & ii)>
<img src="#thumbPath##ii#">
</cfif><br>
</cfloop><br><br>
</cfoutput>
0
 
LVL 2

Author Comment

by:Panos
ID: 21812266
Hi dgrafx.
My DB table is like:
user_id foto1 foto2 foto3........foto8
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21812276
can you change it?
0
 
LVL 2

Author Comment

by:Panos
ID: 21812362
I have allready build the site with this structure and used the values foto1,foto2......in the insertpages update pages a.s.o.The problem i had was with the resizing.I don't know if i can use the same code 8 times with a different filename.That what i need i thing is a <cfset name (fotoupload) for each cffile so that i can use it in the query
.....
Values(#fotoupload1#,#fotoupload2#.........
What do you think?
0
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 500 total points
ID: 21812420
just put in the loop then

before the loop do
<cfset count=0>
insert into table
(userid)
values
(#userID#)

then in loop
<cfset count=count+1>
update table
set foto#count# = '#cffile.serverfile#'
where userID = #userID# (or whatever - just an ex)
0
 
LVL 2

Author Comment

by:Panos
ID: 21812595
Hi dgrafx.
Now you have an update tag.I did hope it was ending and now again something new.I will not understand it if you don't put the new code in my last posted code.
Please make a last try for me.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21812654
well I'm assuming you want to keep these 8 images on one row in the db and not 8 separate rows - is that correct?
or do you want 8 separate rows?
if 8 separate rows then what is with the img1 - img2 et cetera ...

0
 
LVL 2

Author Comment

by:Panos
ID: 21812837
Hi
These 8 photos are for 1 art_Id.Art_id is the primary key for 1 item that is inserted and the fotos are for that specific art_id.So i think they must be on one row where all the other specifications for this art_id are.
I can first make an insert with all the other values:user_id,state,city.... and than update these row with the photos(where art_Id=#art_ID#) on the updatepage or make this direct in the insertpage
I don't know what is better to do.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21812935
yes - do your "other stuff" insert before you even get in the image upload feature.
then within the image loop just update the db
update table
set foto#count# = '#cffile.serverfile#'
where art_id = #art_ID#

you should be good to go ...
0
 
LVL 2

Author Comment

by:Panos
ID: 21813210
look please at the code because i have an error:There are fewer columns in the INSERT statement than values specified in the VALUES clause
<!---

   Create folder structure or change to fit your needs

   Expects images to be uploaded to images and thumbnails go in thumbs

--->

 

 

<!--- set the full path to the images folder --->

<cfset mediapath = expandpath('./images')>

 

<!--- set the desired image height ---->

<cfset thumbsize = 75>

 

<!--- set the desired image width --->

<cfset imagesize = 320>

 <cfset uploadNum=8>

<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->

 

<cfif StructKeyExists(form,"foto" & ZZ) and len(trim(Form["foto" & ZZ]))><!--- 2 --->

    <CFFILE ACTION="UPLOAD"

            FILEFIELD="foto#ZZ#"

            DESTINATION="#mediapath#"

            NAMECONFLICT="makeunique">

   <!--- read the image ---->

   <cfimage name="uploadedImage"

   source="#MediaPath#/#cffile.serverFile#" >

 

   <!--- figure out which way to scale the image --->

   <cfif uploadedImage.width gt uploadedImage.height>

         <cfset thmb_percentage = (thumbsize / uploadedImage.width)>

         <cfset percentage = (imagesize / uploadedImage.width)>

      <cfelse>

         <cfset thmb_percentage = (thumbsize / uploadedImage.height)>

         <cfset percentage = (imagesize / uploadedImage.height)>

  </cfif>

   

   <!--- calculate the new thumbnail and image height/width --->

   <cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>

   <cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>

 

   <cfset newWidth = round(uploadedImage.width * percentage)>

   <cfset newHeight = round(uploadedImage.height * percentage)>

 

   <!--- see if we need to resize the image, maybe it is already smaller than our desired size --->

   <cfif uploadedImage.width gt imagesize>

       <cfimage action="resize"

       height="#newHeight#"

       width="#newWidth#"

       source="#uploadedImage#"

       destination="#MediaPath#/#cffile.serverFile#"

       overwrite="true"/>

  </cfif>

 

    <!--- create a thumbnail for the image --->

  <cfimage action="resize"

    height="#thumbHeight#"

    width="#thumbWidth#"

    source="#uploadedImage#"

    destination="#MediaPath#/thumb/#file.serverFile#"

    overwrite="true"/>

   

 <cfoutput>

     <img src="images/thumb/#cffile.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>

 

      Original Image: #uploadedImage.width#x#uploadedImage.height#<br>

      Resized Image: #newWidth#x#newHeight#<br>

    Thumbnail: #thumbWidth#x#thumbHeight#<br><br>

      <a href="images/#cffile.serverFile#">See Image</a><br>

	</cfoutput>  

	<cfset count=0>

<cfset count=count+1> 

<cfquery  name="qFotos" datasource="#dsn#">

update photo

set foto#count# = '#cffile.serverfile#'

where art_id = 198

</cfquery>

</cfif> 

</cfloop>

  

 

<form action="test1.cfm" method="post" enctype="multipart/form-data">

   <label for="fileUpload">Choose Image: </label>

   <input  type="file" name="foto1"  id="foto1"  />

   <input  type="file" name="foto2"  id="foto2"  />

   <input  type="file" name="foto3"  id="foto3"  />

   <input  type="file" name="foto4"  id="foto4"  />

   <input  type="file" name="foto5"  id="foto5"  />

   <input  type="file" name="foto6"  id="foto6"  />

   <input  type="file" name="foto7"  id="foto7"  />

   <input  type="file" name="foto8"  id="foto8"  />

   <input type="submit" value="Upload Image">

</form>

Open in new window

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21813313
i don't see any code for insert ???

i did notice a problem though
when you count - the initial cfset count=0 needs to be outside the loop or you will always be setting it to 0 and then count+1 will be 1 every time!
0
 
LVL 2

Author Comment

by:Panos
ID: 21813495
I don't know how i can have the insert and update together dgrafx.that's why i did specify the art_Id to make it work for a item that is allready in the DB.
I did try to use your tips but i did misunderstand you.Please can you make this code  to work and please can you make the changes in my code and post the entire code?
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21813779
heres the code but again - i don't see where you are inserting - you did say you were getting an insert error ???
I imagine though that you are inserting before this block of code

<cfset imagesize = 320>
<cfset uploadNum=8>
<cfset count=0>
<cfloop index="ZZ" from="1" to="#uploadNum#"><!--- 1 --->
<cfif StructKeyExists(form,"foto" & ZZ) and len(trim(Form["foto" & ZZ]))><!--- 2 --->
    <CFFILE ACTION="UPLOAD"
            FILEFIELD="foto#ZZ#"
            DESTINATION="#mediapath#"
            NAMECONFLICT="makeunique">
   <!--- read the image ---->
   <cfimage name="uploadedImage"
   source="#MediaPath#/#cffile.serverFile#" >
 
   <!--- figure out which way to scale the image --->
   <cfif uploadedImage.width gt uploadedImage.height>
         <cfset thmb_percentage = (thumbsize / uploadedImage.width)>
         <cfset percentage = (imagesize / uploadedImage.width)>
      <cfelse>
         <cfset thmb_percentage = (thumbsize / uploadedImage.height)>
         <cfset percentage = (imagesize / uploadedImage.height)>
  </cfif>
   
   <!--- calculate the new thumbnail and image height/width --->
   <cfset thumbWidth = round(uploadedImage.width * thmb_percentage)>
   <cfset thumbHeight = round(uploadedImage.height * thmb_percentage)>
 
   <cfset newWidth = round(uploadedImage.width * percentage)>
   <cfset newHeight = round(uploadedImage.height * percentage)>
 
   <!--- see if we need to resize the image, maybe it is already smaller than our desired size --->
   <cfif uploadedImage.width gt imagesize>
       <cfimage action="resize"
       height="#newHeight#"
       width="#newWidth#"
       source="#uploadedImage#"
       destination="#MediaPath#/#cffile.serverFile#"
       overwrite="true"/>
  </cfif>
 
    <!--- create a thumbnail for the image --->
  <cfimage action="resize"
    height="#thumbHeight#"
    width="#thumbWidth#"
    source="#uploadedImage#"
    destination="#MediaPath#/thumb/#file.serverFile#"
    overwrite="true"/>
   
 <cfoutput>
<img src="images/thumb/#cffile.serverFile#" height="#thumbHeight#" width="#thumbWidth#" align="left" hspace="10"><br>
Original Image: #uploadedImage.width#x#uploadedImage.height#<br>
Resized Image: #newWidth#x#newHeight#<br>
Thumbnail: #thumbWidth#x#thumbHeight#<br><br>
<a href="images/#cffile.serverFile#">See Image</a><br>
</cfoutput>  
      
<cfset count=count+1>
<cfquery  name="qFotos" datasource="#dsn#">
update photo
set foto#count# = '#cffile.serverfile#'
where art_id = 198
</cfquery>
</cfif><!--- 2 --->
</cfloop><!--- 1 --->

REMEMBER TO USE CFFILE.SERVERFILE NOT FILE.SERVERFILE!!!!!!!!!!!!!
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31467866
Thank you-Thank you-Thank you-Thank you.
It was difficult for me but in the end i found what you was saying.
regards.
panos
0
 
LVL 2

Author Comment

by:Panos
ID: 21813852
Hi dgrafx.
I was writting my post the same time you did and i did not see your commend.
As you did say i had to put the <cfset count=0> out of the loop.
Now i have closed the question .It would be good to have your last post as the solution!
Thank you again.
Now
0
 
LVL 2

Author Comment

by:Panos
ID: 21813853
Hi dgrafx.
I was writting my post the same time you did and i did not see your commend.
As you did say i had to put the <cfset count=0> out of the loop.
Now i have closed the question .It would be good to have your last post as the solution!
Thank you again.
Now
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 21813891
good news
just keep plugging away ...

one of the downsides of coldfusion is that it is extremely powerful yet very easy for a person just beginning to do useful stuff.
remember always that you need to get your concept down first (and this may be the same no matter what language is used) then you use CF to realize your concept.
I would suggest that you may want to simply state what you want to do and then get suggestions on how-to from a variety of people here.
Then of course is the problem of deciding which is the best solution and if the person posting even knows what they are talking about or not ...
but thats life

good luck ...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now