Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
weswhite7 #1
CF File Upload Question
Ok so heres the deal, I have a page where you can add bios, and theres an image
upload.
Basically my problem is this...
The file path it puts into the databases image field for the directory it is
in is some weird
C:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp62283
..tmp. But in my destination in the cffile tag, its to a drive
e:\wwwroot\[url]www.onwsoccer.com\wwwroot\admin\uploadedfiles\[/url]
When I pull the information from the database it says that that is the path
that it uploaded it to. But if I go to my cfdirectory page it all works out
great. I've attached the code to this so you can see. Somebody please help me
out on this one if you can.
<!--- Add Coach Bio Page --->
<cfif isdefined("FORM.addcoaches")>
<!--- If TRUE, upload the file. --->
<cffile action = "upload" filefield="filecontents"
destination = "e:\wwwroot\www.onwsoccer.com\wwwroot\admin\upload edfiles\"
accept = "image/jpg, image/gif"
nameconflict="overwrite" attributes="normal" >
<cfquery name="addcoaches" username="#username#" password="#pass#"
datasource="#datasource#">
INSERT into coaches (gender, name, position, email, image, biotext)
values ( '#form.gender#', '#form.name#', '#form.position#', '#form.email#',
'#form.filecontents#', '#form.news#' )
</cfquery>
<cfoutput>
<h1>Congratulations, Coach #form.name# has been successfully added!</h1>
</cfoutput>
</cfif>
<cfif isdefined("URL.action")>
<cfif URL.action EQ "addcoaches">
<cfset display = "1">
<form method="post" name="endorsement" enctype="multipart/form-data">
<div align="center">
<input type="hidden" name="addcoaches" value=1>
<span class="bold"><br>
Add Coaches </span></div>
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<td width="25%" valign="top" class="lists">Gender Coached </td>
<td valign="top" class="lists">
<input name="gender" type="radio" value="1" checked>
Men's<br>
<input type="radio" name="gender" value="2">Women's<br>
<input type="radio" name="gender" value="3">Both Men's and Women's
</td>
<br>
</tr>
<tr>
<td width="25%" valign="top" class="lists">Coach Name: </td>
<td valign="top"><input name="name" type="text" id="name"
value="Coach ???" size=30> </td>
</tr>
<tr>
<td width="25%" valign="top" class="lists">Coaching Position:</td>
<br>
<td valign="top">
<select name="position">
<option value="1" selected>Varsity</option>
<option value="2">Assistant Varsity</option>
<option value="3">Junior Varsity</option>
<option value="4">"C" Team</option>
</select>
</td>
</tr>
<tr>
<td width="25%" valign="top" class="lists">Email Address: </td>
<td valign="top"><input name="email" type="text" id="email"
value="??@whatever.com" size=30 maxlength="60"></td>
</tr>
<tr>
<td valign="top" class="lists"><p>Image:</p>
</td>
<td valign="top"><p>
<label>
<input name="filecontents" type="file" class="maintext"
size="50"
value="http://www.onwravens.net/soccer/admin/uploadedfiles/#form.filecontents#">
weswhite7 Guest
-
How to upload a file to 2 FTP sites without an upload component for company
Hi All I can't get round this because it's a local government thing, but I've done a CMS for a school (in ASP classic) that allows them to upload... -
Upload Friendly (Multiple File Upload Applet)
Title : Upload Friendly (Multiple File Upload Applet) Description : UploadFriendly is an easy to use Java Applet that will allow multiple file... -
LWP - multipart/form-data file upload from scalar rather than local file
I'm looking to do an HTTP upload, preferably with HTTP::Request::Common, but get the file data from either a filehandle or a scalar rather than... -
File Upload question
In my project I am uploading file, using HttpPostedFile in ASP.NET. In my project I have to allow user to upload pdf, gif and jepg file only. I... -
how to upload an image selected from html file to flash file?
Hello, I have one html file and a flash file. In html file, it is functioning like choosing a Tshirt to design, then how to load that Tshirt picture... -
mxstu #2
Re: CF File Upload Question
That's the temporary file path used during uploading. Try using the CFFILE variables instead. They will give you the correct server file path.
mxstu Guest
-
weswhite7 #3
Re: CF File Upload Question
I've done that, the path that is listed is the path of the directory on the
server. It uploads the file, and it is on the server with the name and
everything. The cffiledirectory page works fine and outputs the right
information. It's just I can't get the upload from that page to put the correct
path information into the database.
weswhite7 Guest
-
mxstu #4
Re: CF File Upload Question
When you upload a file using CFFILE, it populates a bunch of variables with
information about the file that was uploaded. You should use the CFFILE
variables (and not the form.filecontents variable) to obtain the location of
the file on the server.
See
[url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
wwhelp.htm?context=ColdFusion_Documentation&file=0 0000245.htm
<!--- Not tested so double check this --->
#CFFILE.serverDirectory# / #CFFILE.serverFile#
mxstu Guest
-
weswhite7 #5
Re: CF File Upload Question
Maybe I'm not making too much sense here trying to explain this. The files
upload correctly, to the correct directory. On my directory page everything is
correct. It's my form that is causing the problem. The filefield in the form,
well the value of that is what it writes to the database. Basically I want it
to write the directory that the file went into, with the file name on there for
example [url]http://www.onwravens.net/soccer/admin/uploadedfiles/filename.extension[/url]
weswhite7 Guest
-
mxstu #6
Re: CF File Upload Question
No, I think you were clear. It was late and I may not have explained it
properly. After you upload the file, you need to use CFFILE variables to
determine where the file went.
<!--- test page --->
<form action="#GetFileFromPath(GetBaseTemplatePath())#" method="post"
enctype="multipart/form-data">
File: <input type="file" name="filecontents">
<input type="submit" value="Upload File">
</form>
<cfif IsDefined("form.filecontents")>
<cffile action = "upload" filefield="filecontents"
destination = "c:\temp"
accept = "image/jpg, image/gif"
nameconflict="overwrite" attributes="normal">
<cfoutput>
<b>This is the temporary file that you're seeing:</b><br>
#form.filecontents#<br>
<hr>
<b>The CFFILE variables will give you the correct file and path:</b><br>
#CFFILE.serverDirectory#\#CFFILE.serverFile#<br>
<hr>
</cfoutput>
</cfif>
mxstu Guest
-
mxstu #7
Re: CF File Upload Question
Hmm, on second thought ... maybe I'm not clear on what you are asking :-)
Are you trying to write a "directory" -
e:\wwwroot\[url]www.onwsoccer.com\wwwroot\admin\uploadedfiles\[/url]
or a "URL" -
[url]http://www.onwravens.net/soccer/admin/uploadedfiles/filename.extension[/url]
to the database?
mxstu Guest
-
OldCFer #8
Re: CF File Upload Question
Like mxstu says, you can't use form.filecontents directly. You need to do
something like this.
After the cffile upload tag:
<cfset FileLocation =
"e:\wwwroot\www.onwsoccer.com\wwwroot\admin\upload edfiles\" &
CFFILE.ServerFile>
Now you put FileLocation into the DB, instead of form.filecontents.
OldCFer Guest
-
weswhite7 #9
Re: CF File Upload Question
Thanks for your continued efforts.
I want to write the url to the directory. It's now starting to make better
sence to me. Again, I'm sorry for all the problems with this but I've been
doing CF for about 2 months now, just finished up my basic admin system, and
now I'm trying to spiff it up, a lot. I'm only 17.
So, with the combination of mxstu and oldcfer, it really hit me on the last 3
posts. So then I do the cfset after the cffile and set filelocation to the
directory path of files, but whats the & CFFILE.serverfile do that comes after
that? So now in the write to database code, where I list the fields that the
data will be placed into ,and then the ( '#form.whatever#') and all that
nonsense, to write the path, I would set the filepath with cfset, and then in
the write to, on the one that matches up for the image path, I would do
('#filepath#')? Is that correct?
weswhite7 Guest
-
OldCFer #10
Re: CF File Upload Question
When you did the cffile "upload", you specified the file was to be put in:
"e:\wwwroot\www.onwsoccer.com\wwwroot\admin\upload edfiles\".
After you do the cffile upload CF creates a variable called CFFILE.Serverfile
which contains the name of the file so you want to add that on to the end
of the destination directory, then store the whole thing on the DB.
OldCFer Guest
-
weswhite7 #11
Re: CF File Upload Question
Larry -
Thank you so much for your help. I finally got that to work after I sat down
and played with it for a while using the cfset and cffile.serverfile and
outputting that into the field to the database.
Thanks Again,
Wes
weswhite7 Guest



Reply With Quote

