Solved

(dgrafx) please help "Can't do the upload to a file"

Posted on 2014-02-26
17
327 Views
Last Modified: 2014-02-27
Hi,

It is not uploading to my database. I thought it's working but it's not.

here is my code:

         <cfoutput>
                  <cfloop from="1" to="3" index="ii">
      <INPUT TYPE="FILE" NAME="AttachFile#ii#" class="file" style="width:500px;"><br>
</cfloop></cfoutput>




<cfset filelocation="UploadedFiles\">
<cfset maxFiles = 3>
<cfset Attachments="">
      <cfloop from="1" to="#variables.maxFiles#" index="ii">
      <cftry>
            <cfif StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))>
      hello
             <CFFILE ACTION="UPLOAD"
                        FILEFIELD="AttachFile#ii#"
                        DESTINATION="#variables.filelocation#"
                        NAMECONFLICT="makeunique">
     
             <cfset Attachments=ListAppend(variables.Attachments,cffile.serverfile)>  
         
         </cfif>
            <cfcatch>
            <br>#cfcatch.message#<br>#cfcatch.detail#<br>
            #cfcatch.tagContext[1].template# Line #cfcatch.tagContext[1].line#
            </cfcatch></cftry>
      </cfloop>
                  
         
            <cfif len(trim(variables.Attachments))>
           
      <cfquery name = "QLogFiles"  datasource="#strDSN#" username="#strUID#" password="#strPWD#">
                  Set Nocount On;
                   <cfloop list="#variables.Attachments#" index="ii">
       <cfif FileExists(variables.filelocation & ii)>
                  INSERT INTO Files
                        (UploadedFile)
                  VALUES
                        (<cfqueryparam cfsqltype="cf_sql_blob"
                                value="#FileReadBinary(variables.filelocation & ii)#">)
          </cfif>
      </cfloop>
</cfquery>
</cfif>

<cfabort>
0
Comment
Question by:lulu50
  • 9
  • 8
17 Comments
 

Author Comment

by:lulu50
ID: 39889291
the error:

<cfif FileExists(variables.filelocation & ii)>

  value="#FileReadBinary(variables.filelocation & ii)#">)


An error occurred when performing a file operation readBinary on file
The cause of this exception was: java.io.FileNotFoundException:
The system cannot find the path specified
0
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 39889356
one thing i notice is that the value of filelocation is incorrect - it would be something like "d:\websites\files\" or if on a server and you are not sure what the file location is you can then do expandPath("uploadedfiles")
the code executing needs to know where the uploadedfiles folder is though - like if it's in a different folder then it can't find it.
so start from website root like: expandPath("/uploadedfiles")
that means that the folder is in the root of the website
do you know what i mean?

so the cffile and the fileexists can work with a path like "uploadedfiles/" and filereadbinary cannot - which is odd yes ...

anyway - try that and let me know
0
 

Author Comment

by:lulu50
ID: 39889436
I used this

 <cfset filelocation = expandpath('uploadedfiles/')>

now I have a different error

Error Executing Database Query.  On line 36 is the error

<cfquery name = "QLogFiles"  datasource="#strDSN#" username="#strUID#" password="#strPWD#">
35 :                   Set Nocount On;
36 :                    <cfloop list="#variables.Attachments#" index="ii">
37 :       <cfif FileExists(variables.filelocation & ii)>


I tried to dump it so I can see the output of this #variables.Attachments#
but that didn't work

I need to see what's in the #variables.Attachments#


the error

Error Executing Database Query.  
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '/'.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889469
is this Sql Server?

What is the error on line 36? or is that all it says?
0
 

Author Comment

by:lulu50
ID: 39889473
The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.  

Error Occurred While Processing Request  
Error Executing Database Query.  
[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '/'.  
 
The error occurred in D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 39
Called from D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 5
Called from D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 4
Called from D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 39
Called from D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 5
Called from D:/inetpub/wwwroot-dev/mpdb/Impact/SubEntry.cfm: line 4
 
37 :        
38 :            
39 :                    <cfloop list="#variables.Attachments#" index="ii">
40 :       <cfif FileExists(variables.filelocation & ii)>
41 :
 

--------------------------------------------------------------------------------
 
VENDORERRORCODE   102
SQLSTATE   HY000
SQL    Set Nocount On; D:\inetpub\wwwroot-dev\mpdb\Impact\UploadedFiles\doc5.doc INSERT INTO Files (UploadedFile) VALUES ( (param 1) ) D:\inetpub\wwwroot-dev\mpdb\Impact\UploadedFiles\hint5.doc INSERT INTO Files (UploadedFile) VALUES ( (param 2) )  
DATASOURCE   mpdb-impact
 
Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.

 
Browser   Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; MS-RTC LM 8)
Remote Address   10.68.132.150
Referrer   Date/Time   26-Feb-14 12:49 PM
 
Stack Trace (click to expand)
0
 

Author Comment

by:lulu50
ID: 39889500
Oh wow,

it's working!!!!

I see the files in the database!!!!!!!!!!!!!!!!!!!!!!!

I'ts magic
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889528
in the sql that you are showing:
Set Nocount On; D:\inetpub\wwwroot-dev\mpdb\Impact\UploadedFiles\doc5.doc INSERT INTO Files (UploadedFile) VALUES ( (param 1) ) D:\inetpub\wwwroot-dev\mpdb\Impact\UploadedFiles\hint5.doc INSERT INTO Files (UploadedFile) VALUES ( (param 2) )  

WHERE are the string in bold coming from?
Doesn't make sense!

to see what is in variables.attachments just use
<cfoutput>#variables.Attachments#</cfoutput><cfabort>
also post what is the value of filelocation.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889532
what did you do differently?
0
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

 

Author Comment

by:lulu50
ID: 39889585
I added this
<cfset filelocation = expandpath('uploadedfiles/')>

and not sure what else lol lol lol lol
0
 

Author Comment

by:lulu50
ID: 39889598
I need to do some more testing before I close this question. so, please stay with me lol lol lol

Thank you for all your help

lulu
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889617
ha!

but you said you had already added that!
it's in your code above!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889626
btw it should be
<cfset filelocation = expandpath('/uploadedfiles')>
IF in root
can get used to using " dbl quotes in CF code!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39889803
i had a thought - did you move the code to a different location?
like from a place you were testing or ???

that's why i said to use the beginning forward slash which means root directory and to then build location after that.

/ = this means website root

/files = this means in a folder named files that resides in the root

/files/uploads = this means folder uploads in folder files that is in root

files/uploads = this folder files is not necessarily in the root - it is in the same place as the file that you are running the code on and uploads is in that folder.
so if you move the .cfm file or copy and paste the code into a file that sits elsewhere this path is now broken!
that is why you need to start from root - so it doesn't matter where the code lies - the path to the files is always understood.

i hope you understand that - kinda hard to explain

<cfset filelocation = expandpath("/uploadedfiles")>
note the forward slash at the beginning!
no matter where you call this code from it will look in the root directory in a folder named uploadedfiles.

if you do this <cfset filelocation = expandpath("uploadedfiles/")>
this doesn't mean the same thing! code called from different locations will look for this folder in different locations!
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39891607
is it working?
and do you understand what i mean about the leading forward slash and the root directory?
0
 

Author Comment

by:lulu50
ID: 39891808
dgrafx,

I understand exactly what you mean but

when I do this: (I am not able to insert my file)
<cfset filelocation = expandpath("/uploadedfiles")>

but

when I do this: (My file is inserting into my database)
 <cfset filelocation = expandpath('uploadedfiles/')>

Thank you so much for all your help.

lulu
0
 

Author Closing Comment

by:lulu50
ID: 39891812
Thank you for one million and one times lol lol
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 39891882
let's discuss this a bit ...

when you say
when I do this: (I am not able to insert my file)
<cfset filelocation = expandpath("/uploadedfiles")>

that means that the folder uploadedfiles is NOT in the root directory.
maybe the entire app you are working on is not in the root directory as far as iis sees it.

do this: #expandPath("/")#
what does it say?
whatever it says is the website root - according to iis (or whatever webserver)

i worked on a campus once upon a time where the actual website root was on a level above all the individual folders that housed the different websites - so you just needed to take that into account when coding.
it was something like:
websites
      site1
      site2
      site3
and so #expandPath("/")# resolved to D:\websites\
and so for site 1 it needed to be #expandPath("/site1")# which would then be D:\websites\site1\

so in your case it may be something like that
what is the value of #expandPath("/")# in your environment?
let's say that the folder name of your site files is "QLog".
it may then be that your intended site root is #expandPath("/QLog")#

just trying to help - this is what I do ...

this beginning forward slash and web root is a greatly misunderstood area.
there is confusion about one's intended web root vs actual web root.
in the example i gave above the site1, 2, 3 were the intended web roots but not the actual web root.

please post back with feedback & or questions
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

20 Experts available now in Live!

Get 1:1 Help Now