Solved

UPloading attachments

Posted on 2006-11-22
11
253 Views
Last Modified: 2013-12-24
Experts,

Can someone tell me if there is a way to allow users to  upload attachments from my app to my server?  Users are answering questions ,and one particular question asks them to upload a file.  I would like to store all of the answers along with the file that they uploaded in 1 table if that is possible.  Any suggestions would be appreciated.

Thanks
Nick
0
Comment
Question by:nmarano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 250 total points
ID: 17996869
you need to add the ENCTYPE="multipart/form-data" as below and the type="file" field
<form action="actionpage.cfm" ENCTYPE="multipart/form-data" method="post" name="Form">
<INPUT TYPE="FILE" NAME="AttachFile">
<INPUT TYPE="Submit">
</form>

this is a basic form actionpage.cfm
<cfset filename=""><!--- this is a default so that if file is not uploaded --->
<cfif StructKeyExists(form,"AttachFile") and len(trim(form.AttachFile))>
<cfset filelocation="d:\web\files\"><!--- this is just the absolute path to where the file will go --->
<CFFILE ACTION="UPLOAD"
FILEFIELD="AttachFile"
DESTINATION="#filelocation#"
NAMECONFLICT="makeunique"><!--- skip or overwrite are other options for nameconflict --->
<cfset filename=cffile.serverfile>
</cfif>

then when you insert form data to db - '#filename#' is what you'd insert for the name of the file they uploaded
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 17998173
to add to what dgrafx mentioned in regards to storing that image data with your other related question data...

>I would like to store all of the answers along with the file that they uploaded in 1 table if that is possible.

you'd want to store the absolute path, or if the absolute path will always be the same, store the directory name and image name/ext, in your database along with whatever questions info it relates to in your database...

for instance, storing the filename and filelocation along with your question info...

<cfquery name="youQry" datasource="">
  INSERT INTO tableName ( [tableColumnsHereForOtherValues], fileName, filePath )
  VALUES ( [otherValuesAssociatedToQues], '#filename#', '#filelocation#' )
</cfquery>

this way the image is stored on your server, and you have the location stored along with your other question info stored in your table...

you could then query that info later and the table will have the data to display that image where you need it based on the fileName and fileLocation stored with your question info...
0
 
LVL 2

Author Comment

by:nmarano
ID: 18000398
Thanks,

I will take a look at this and get back to you both.  Thanks again

Nick
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 2

Author Comment

by:nmarano
ID: 18020632
dgrafx, trail

Thank you both for your suggestions, I almost have this working.  I am setting up a small test page to try and get this to work, and was hoping for a little more help.  Trail, this may sound as a really dumb question, but where you have fileName, filePath in the insert statment, am I supposed to put the actual filePath where I want this to be stored?  I tried running it, but got this error

Error Executing Database Query.  
Syntax error or access violation: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '[fname,lname,email,attach], fileName, filePath ) VALUES ( [f  
 
The error occurred in C:\Inetpub\wwwroot\nmarano\Code\attachment_action.cfm: line 13
 
11 : <cfquery name="youQry" datasource="APTVRE">
12 :   INSERT INTO attachFile ( [fname,lname,email,attach], fileName, filePath )
13 :   VALUES ( [fname,lname,email,AttachFile], '#filename#', '#filelocation#' )
14 : </cfquery>

 

--------------------------------------------------------------------------------
 
SQL    INSERT INTO attachFile ( [fname,lname,email,attach], fileName, filePath ) VALUES ( [fname,lname,email,AttachFile], 'cross1.jpg', 'c:\NickAttach\' )  
DATASOURCE   APTVRE
 

My action page looks like this...........

<cfset filename="">
<cfif StructKeyExists(form,"AttachFile") and len(trim(form.AttachFile))>
<cfset filelocation="c:\NickAttach\">
<CFFILE ACTION="UPLOAD"
FILEFIELD="AttachFile"
DESTINATION="#filelocation#"
NAMECONFLICT="makeunique">
<cfset filename=cffile.serverfile>
</cfif>

<cfquery name="youQry" datasource="APTVRE">
  INSERT INTO attachFile ( [fname,lname,email,attach], fileName, filePath )
  VALUES ( [fname,lname,email,AttachFile], '#filename#', '#filelocation#' )
</cfquery>


Thanks
nick
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 18020687
It's due to the []'s in the SQL, I just had those in there for a place holder, they should not be in the code, try this...

<cfset filename="">
<cfif StructKeyExists(form,"AttachFile") and len(trim(form.AttachFile))>
<cfset filelocation="c:\NickAttach\">
<CFFILE ACTION="UPLOAD"
FILEFIELD="AttachFile"
DESTINATION="#filelocation#"
NAMECONFLICT="makeunique">
<cfset filename=cffile.serverfile>
</cfif>

<cfquery name="youQry" datasource="APTVRE">
  INSERT INTO attachFile (fname, lname, email, fileName, filePath )
  VALUES ('#form.fname#', '#form.lname#', '#form.email#', '#filename#', '#filelocation#' )
</cfquery>
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 18020705
you also don't need "AttachFile" in your table, the "fileName" should be all you need, the "AttachFile" is the file you're uploading, however due to the ENCTYPE="multipart/form-data" it will not be of much use, it's more used for the <cffile>, the "fileName" and "fileLocation" is all you'd need to reference that file at a later time...
0
 
LVL 2

Author Comment

by:nmarano
ID: 18020770
Trail,

Sorry about that, I realized it after I had posted, but I am still getting an error.  The error I get is................

Error Executing Database Query.  
Syntax error or access violation: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''c:\NickAttach\' )' at line 2  
 
The error occurred in C:\Inetpub\wwwroot\nmarano\Code\attachment_action.cfm: line 13
 
11 : <cfquery name="youQry" datasource="APTVRE">
12 :   INSERT INTO attachFile (fname, lname, email, fileName, filePath )
13 :   VALUES ('#form.fname#', '#form.lname#', '#form.email#', '#filename#', '#filelocation#' )
14 : </cfquery>
15 :


--------------------------------------------------------------------------------
 
SQL    INSERT INTO attachFile (fname, lname, email, fileName, filePath ) VALUES ('Nick', 'Marano', 'marano@emial', 'cross4.jpg', 'c:\NickAttach\' )  
DATASOURCE   APTVRE
VENDORERRORCODE   1064
SQLSTATE   42000
 
Any idea what would be throwing this error?

Thanks
nick

 
0
 
LVL 20

Accepted Solution

by:
trailblazzyr55 earned 250 total points
ID: 18020773
in regards to your question: "Trail, this may sound as a really dumb question, but where you have fileName, filePath in the insert statment, am I supposed to put the actual filePath where I want this to be stored?"

the "fileName" stores the actual file name of what was uploaded, example: "myImage.jpg"
the "filePath" stores the actual path to the file on your server, example: "c:\NickAttach\"

you save these values so later you can query this record and have the path and file name to display the file/image on your server

just before your <cffile> you're defining what directory you want to store the file in, you have it set to: "c:\NickAttach\"
you can also reference the location where the file was stored by "cffile.serverDirectory"

so you could do this as well...

<cfset filename="">
<cfif StructKeyExists(form,"AttachFile") and len(trim(form.AttachFile))>
<cfset filelocation="c:\NickAttach\">
<CFFILE ACTION="UPLOAD"
FILEFIELD="AttachFile"
DESTINATION="#filelocation#"
NAMECONFLICT="makeunique">
<cfset filename=cffile.serverfile>
<cfset filelocation=cffile.serverDirectory>
</cfif>

<cfquery name="youQry" datasource="APTVRE">
  INSERT INTO attachFile (fname, lname, email, fileName, filePath )
  VALUES ('#form.fname#', '#form.lname#', '#form.email#', '#filename#', '#filelocation#' )
</cfquery>
0
 
LVL 2

Author Comment

by:nmarano
ID: 18020828
Trail,

This last line that you added to dgrafx code, somehow did the trick

<cfset filelocation=cffile.serverDirectory>

For some reason, but adding that line, it no longer gives me an error and it writes to the db and the file gets uploaded properly.

Thank you both for the help

nick
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 18020844
in regards to the error, check the column type on your table to make sure it's the correct data type, example: text, varchar, etc.. depending on the type of database....

also is "attachFile" the name of your table?

also try this...

<cfquery name="youQry" datasource="APTVRE">
  INSERT INTO [attachFile] (fname, lname, [email], [fileName], [filePath] )
  VALUES ('#form.fname#', '#form.lname#', '#form.email#', '#filename#', '#filelocation#' )
</cfquery>

0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 18020849
ahh ok, great, yeah I was thinking it was either a funky naming or value that was getting passed in...
Glad we were able to help!
good luck ;o)
~trail
0

Featured Post

Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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