ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 24th, 2004, 12:44 PM
elise_driver elise_driver is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Norwich
Posts: 53 elise_driver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 27 m 10 sec
Reputation Power: 5
Cool Uploading an image

I have a form that allows a user to insert data into a SQL database using coldfusion. I need to allow the user of the form to upload an image from their hard drive to the server.

Is code available so that I can do this?

Hope someone can help.

Cheers

peter

Reply With Quote
  #2  
Old April 25th, 2004, 10:50 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,492 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 25 m 21 sec
Reputation Power: 44
FORM PAGE:
<form method="post" action="uploadaction.cfm" name="uploadForm" enctype="multipart/form-data">
<input name="FileContents" type="file">
<br>
<input name="submit" type="submit" value="Upload File">
</form>

POST PAGE (replace your destination directory and name conflict settings as necessary):
<cffile action = "upload" fileField = "FileContents" destination = "c:\files\upload\" accept = "text/html" nameConflict = "MakeUnique">

Reply With Quote
  #3  
Old April 25th, 2004, 03:53 PM
elise_driver elise_driver is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Norwich
Posts: 53 elise_driver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 27 m 10 sec
Reputation Power: 5
Question almost there

Thanks for all your help.

I understand your code apart from what the conflict settings part.

What are conflict settings and how do I set them?

Is there also a way to restrict the size of an image that the user can upload (either physical size i.e 1mb or dimensions of the image)?

A friend of mine using asp bought a program of the internet to upload an image as it uses streaming of the data I think? Is this necessary or available for uploading images in coldfusion?


Cheers

Peter

Reply With Quote
  #4  
Old April 27th, 2004, 02:59 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,492 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 25 m 21 sec
Reputation Power: 44
The conflict settings are described fully in the CF documentation.

I don't believe there's any way to limit the file size, as the server knows nothing about the file when the transfer starts. You could probably write code that handled some restrictions AFTER the file is uploaded (by looking at the file size and/or the image size), but it would require coding to do it; such functionality is not provided out of the box.

You don't need any special add-ons to upload an image or any other type of file to the CF server. Just the code I listed above, and your decisions on what to do with the file after it is uploaded.

Reply With Quote
  #5  
Old April 28th, 2004, 01:17 PM
elise_driver elise_driver is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Norwich
Posts: 53 elise_driver User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 27 m 10 sec
Reputation Power: 5
Red face only one more small question

Thanks very much for your help. I have got the code working well.

The only other question I have is how do I do error checking so that i can display my own message when the user trys to upload a file type which isn't included in the accept =.

Thanks very much.

Cheers
Peter

Reply With Quote
  #6  
Old April 29th, 2004, 08:30 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,492 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 25 m 21 sec
Reputation Power: 44
You can have the cffile tag throw an error (I believe that is the default setting). Then use a try/catch block to catch the error and redirect them, display an error message, or whatever else you need to do:

<cftry>
<cffile action="UPLOAD" filefield="fileContents" destination="c:\" accept = "image/jpg, application/msword">
<cfcatch type="any">
The upload didn't work or the server could not accept your file type.
</cfcatch>
</cftry>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Uploading an image


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway