| Posted By |
Discussion Topic: Uploading Files
-- page:
1
2
|
|
apletfx |
12-15-2002 @ 2:20 AM |
|
|
Moderator
Posts: 607
Joined: Nov 2002
|
I was hoping one of you have seen a tutorial online that explained how to upload files from a user to the server? If you could post a link here that would be great! Thanks in advance. Mark Aplet
|
maquiladoras |
12-15-2002 @ 12:09 PM |
|
|
Moderator
Posts: 2073
Joined: Dec 2002
|
ok heres how i'd do it create your html and put the following in for your form Upload.html ----------- <FORM action="upload2.cfm" enctype="multipart/form-data" method="post"> <INPUT type="File" name="filename" size="20"> <INPUT type="Submit" value="Upload File"> </FORM> upload2.cfm ----------- <CFFILE action="UPLOAD" filefield="filename" destination="c:\yourdirectory" nameconflict="MAKEUNIQUE"> <TABLE width="500" border="0" height="229" cellpadding="10"><TR> <CFIF cffile.filewasSaved> <TD height="47" class="headlines" align="center">Your File Upload Was Successful!<br><cfoutput> you have succesfully uploaded #file.serverfile#<br></cfoutput> </TD></TR><TR><TD height="196" align="center" valign="top" class="bodytext"> <A href="http://www.yourpage.com"> Return to Your homepage</A></TD> <CFELSE> <TD height="47" class="headlines" align="center"> Your File Upload Was A Failure! </TD></TR><TR> <TD height="196" align="center" valign="top" class="bodytext"> <A href="http://upload.html"> Return to the upload page.</A></TD></CFIF> </TR></TABLE> hope this helps you
|
Webmaster |
12-15-2002 @ 8:27 PM |
|
|
Administrator
Posts: 4533
Joined: Jan 2002
|
OK, Note this: destination="c:\yourdirectory" This has to have a trailing slash or you'll get an error: change it to: destination="c:\yourdirectory\" :)
Thanks, Pablo Varando EasyCFM.COM, LLC.
|
maquiladoras |
12-15-2002 @ 10:11 PM |
|
|
Moderator
Posts: 2073
Joined: Dec 2002
|
erm, on my dev site, i have it so that it does application.cfm --------------- <CFSET APPLICATION.thumbpath= "e:\webdev\test\images\thumbs"> addprod2.cfm ------------ <CFFILE action="upload" FILEFIELD="FileName" DESTINATION="#application.thumbpath#" NAMECONFLICT="makeunique"> So I am genuinely confused
|
Webmaster |
12-15-2002 @ 11:28 PM |
|
|
Administrator
Posts: 4533
Joined: Jan 2002
|
ColdFusion MX will auto-replace it, but 5.0 or earlier wont, so it's always good to put it...
Thanks, Pablo Varando EasyCFM.COM, LLC.
|
maquiladoras |
12-16-2002 @ 7:26 AM |
|
|
Moderator
Posts: 2073
Joined: Dec 2002
|
thanks for clearing that one up
|
Redmanz |
12-16-2002 @ 10:18 AM |
|
|
Senior Member
Posts: 411
Joined: Oct 2002
|
Okay than how would you incorporate the image upload into a existing form. So when it uploads to the site it also writes the image name "image.jpg" into the database along with the information from the other fields. In the sample you will see I have the user inputing in the image name...would be nice if they just browsed to a image or images and the name was sent to the db as well as being uploaded. Sample form I'm working on below......sorry it's rather long but................
<form name="form" method="post" action="<cfoutput>#getfilefrompath(cgi.script_name)#</cfoutput>"> <input type="hidden" name="PageName" value="<cfoutput>#getfilefrompath(cgi.script_name)#</cfoutput>"> <input name="available" type="hidden" value="YES"> <table width="600" border="1" align="center" cellpadding="2" cellspacing="0"> <tr align="center"> <td colspan="4"><h3>Add New Property</h3></td> </tr> <tr> <td width="150" align="right">Area :</td> <td width="450" colspan="3"> <select name="area_id"> <option value="">Please Select</option> <cfoutput query="get_area"> <option value="#get_area.areaID#">#get_area.area#</option> </cfoutput> </select> </td> </tr> <tr> <td align="right">Dwelling Type :</td> <td colspan="3"> <select name="category_id"> <option value="">Please Select</option> <cfoutput query="get_category"> <option value="#get_category.categoryID#">#get_category.name#</option> </cfoutput> </select> </td> </tr> <tr> <td align="right">Price :</td> <td colspan="3"><input name="price" type="text" id="price"></td> </tr> <tr> <td align="right">Street Address :</td> <td colspan="3"><input name="street" type="text" id="street"></td> </tr> <tr> <td align="right" valign="top">Short Description :</td> <td colspan="3"><textarea name="short_desc" cols="50" rows="2" id="short_desc"></textarea></td> </tr> <tr> <td align="right" valign="top">Long Description :</td> <td colspan="3"><textarea name="long_desc" cols="50" rows="2" id="long_desc"></textarea></td> </tr> <tr> <td align="right">Small Image :</td> <td colspan="3"><input name="thumb" type="text" id="thumb"> image name only i.e. property.jpg</td> </tr> <tr> <td align="right">Large Image :</td> <td colspan="3"><input name="full_image" type="text" id="full_image"> image name only i.e. property.jpg </td> </tr> <tr> <td width="150" align="right">Number Bedrooms: </td> <td width="150" align="left"><select name="bedrooms" size="1" id="bedrooms"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></td> <td width="150" align="right">Number Bathrooms: </td> <td width="150" align="left"><select name="bathrooms" size="1" id="bathrooms"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> </select></td> </tr> <tr> <td align="right">Bedroom Sizes: </td> <td colspan="3">#1: <input name="bedroom1" type="text" id="bedroom1" size="20"> #2: <input name="bedroom2" type="text" id="bedroom2" size="20"> #3: <input name="bedroom3" type="text" id="bedroom3" size="20"></td> </tr> <tr> <td align="right">Bedroom Sizes: </td> <td colspan="3">#4: <input name="bedroom4" type="text" id="bedroom4" size="20"> #5: <input name="bedroom5" type="text" id="bedroom5" size="20"> #6: <input name="bedroom6" type="text" id="bedroom6" size="20"></td> </tr> <tr> <td align="right">Living Room Size: </td> <td><input name="livingroom" type="text" id="livingroom" size="20"></td> <td align="right">Dining Room Size: </td> <td><input name="diningroom" type="text" id="diningroom" size="20"></td> </tr> <tr> <td align="right">Kitchen Size: </td> <td><input name="kitchen" type="text" id="kitchen" size="20"></td> <td align="right">Number of Floors: </td> <td><select name="stories" size="1" id="stories"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select></td> </tr> <tr> <td align="right">Building Size: </td> <td><input name="size" type="text" id="livingroom3" size="20"></td> <td align="right">Lot Size: </td> <td><input name="lot_size" type="text" id="livingroom4" size="20"></td> </tr> <tr> <td align="right">Year Built: </td> <td><input name="year_built" type="text" id="livingroom5" size="20"></td> <td align="right">Property Taxes: </td> <td><input name="taxes" type="text" id="livingroom6" size="20"></td> </tr> <tr> <td align="right">Parking: </td> <td><input name="parking" type="text" id="livingroom7" size="20"></td> <td align="right">Exterior Finish: </td> <td><input name="exterior" type="text" id="livingroom8" size="20"></td> </tr> <tr> <td align="right">Roofing Material: </td> <td><input name="roof" type="text" id="livingroom9" size="20"></td> <td align="right">Primary Heat: </td> <td><input name="heat" type="text" id="livingroom10" size="20"></td> </tr> <tr align="center"> <td colspan="4"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form>

A funny thing happened on my way to the forum Ceaser...........
|
maquiladoras |
12-16-2002 @ 12:13 PM |
|
|
Moderator
Posts: 2073
Joined: Dec 2002
|
ok i did a similar thing for shopping cart application first thing
Application.cfm ---------------- <!--- default URL of Thumbnails ---> <CFSET APPLICATION.thumb= "http://yoururl.com/images/thumbs">
<!--- default URL of Full Images ---> <CFSET APPLICATION.full= "http://yoururl/images/full">
<!--- default Physical Location of Thumbnails ---> <CFSET APPLICATION.thumbpath= "c:\yourdir\images\thumbs\">
<!--- default Physical Location of Full Images ---> <CFSET APPLICATION.fullpath= "c:\yourdir\images\full\">
Add_product.cfm ---------------- put in your form fields, that submits to addprod2.cfm (do not put any image upload here
Addprod2.cfm ------------ Start with inserting into the database the previous form, then include an upload form
<FORM ACTION="finish.cfm" enctype="multipart/form-data" METHOD="Post">
File to upload : <INPUT type="File" name="filename" size="20"> <INPUT type="Submit" value="Upload File"></CFOUTPUT>
put an hidden input that has the id that you just created from the previous form
finish.cfm ----------
Download CFX_image from anywhere on the net, is readily available and free
and use the following code
<CFFILE action="UPLOAD" filefield="filename" destination="#application.fullpath#" nameconflict="MAKEUNIQUE">
<CFFILE action="upload" FILEFIELD="FileName" DESTINATION="#application.thumbpath#" NAMECONFLICT="makeunique">
<CFSET filepath="#application.thumbpath#">
<CFSET file_to_thumbnail = "#filepath#\#file.serverfile#">
<CFSET thumb_filename = "#filepath#" & "\thumb_" & "#file.serverfile#">
<CFSET thumb_displaypath = "#application.thumb#" & "/thumb_" & "#file.serverfile#">
<CFX_IMAGE ACTION="IML" FILE="#file_to_thumbnail#" COMMANDS=" setvar x=100 setvar y=100 resize <x> write #thumb_filename#">
<CFQUERY NAME="AddFullImage" DATASOURCE="#application.dsn#"> UPDATE yourtable SET full_img='#application.full#/#file.serverfile#' WHERE id='#Form.id#' </CFQUERY>
<CFQUERY NAME="AddThumbimage" DATASOURCE="#application.dsn#"> UPDATE yourtable SET thumb_img='#application.thumb#/thumb_#file.serverfile#' WHERE id='#Form.id#' </CFQUERY>
then at the end of the file add
<CFFILE ACTION="DELETE" FILE="#filepath#\#file.serverfile#"> </CFOUTPUT>
------------------------------------------------------
this is probably not what you want BUT it allows you to upload an image that automatically creates a thumbnail as well with it then add thes URL's of the images to the database so you can do
<img border="0" src="#thumb_img#"> <img border="0" src="#full_img#">
hope this helps
This message was edited by maquiladoras on 12-16-02 @ 12:18 PM
|
apletfx |
12-28-2002 @ 9:27 PM |
|
|
Moderator
Posts: 607
Joined: Nov 2002
|
Let me just say, I am so glad you gentelmen touched on this subject. It is one of the main reasons I wanted to learn ColdFusion. I do alot of thumbnailing of photos for band web sites and I really hope this will cut down on the amount of work I have to do. However, I still have some questions on the above code. I would like to know how this code could be simplified to preform the tasks in simpler, more managable tasks. Basicly, I would like to be able to upload a picture and a caption at the same time. With some sites I will have No caption at all, and will only require the ability to upload the photo. It would be nice not to forced to go through several steps. Short term Memory loss from prior marijuana habits make it difficult for my users to remember what the caption was prior to uploading the file. In the above code, you upload and insert the text first, You then would have to upload the picture file seperatly. It seams more logical to upload the text (Caption) at the same time as the photo. that way you would only have to code two pages insted of three. Additionaly, in the event you are not uploading text at all, there will be nothing in the DB to get the Form.id from. I think the part that gets me confused is the update in the finish.cfm. Where is the FORM.id comming in from? I suppose you could do a query but that seams odd, and an extra step to code and more work for the server. Sorry if this is confusing to you, as it is to me. Does anyone understand my question? Thanks
This message was edited by apletfx on 12-28-02 @ 10:12 PM
|
maquiladoras |
12-28-2002 @ 10:39 PM |
|
|
Moderator
Posts: 2073
Joined: Dec 2002
|
please be aware i quickly knocked that code up with the help of redmanz ive streamlined the code a little bit the best thing to do is rather based on text use <cfquery datasource="#application.dsn#" name="GetLastID"> SELECT MAX(id) as lastID FROM yourtable </cfquery> <cfset image_id = #GetLastID.lastID#> therefor its just based on the last one you did best thing to do is is just take all the form elements from the first two pages and combine the actions in order in the last page
|