Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

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

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
lulu50
Asked:
lulu50
  • 9
  • 8
1 Solution
 
lulu50Author Commented:
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
 
dgrafxCommented:
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
 
lulu50Author Commented:
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
dgrafxCommented:
is this Sql Server?

What is the error on line 36? or is that all it says?
0
 
lulu50Author Commented:
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
 
lulu50Author Commented:
Oh wow,

it's working!!!!

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

I'ts magic
0
 
dgrafxCommented:
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
 
dgrafxCommented:
what did you do differently?
0
 
lulu50Author Commented:
I added this
<cfset filelocation = expandpath('uploadedfiles/')>

and not sure what else lol lol lol lol
0
 
lulu50Author Commented:
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
 
dgrafxCommented:
ha!

but you said you had already added that!
it's in your code above!
0
 
dgrafxCommented:
btw it should be
<cfset filelocation = expandpath('/uploadedfiles')>
IF in root
can get used to using " dbl quotes in CF code!
0
 
dgrafxCommented:
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
 
dgrafxCommented:
is it working?
and do you understand what i mean about the leading forward slash and the root directory?
0
 
lulu50Author Commented:
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
 
lulu50Author Commented:
Thank you for one million and one times lol lol
0
 
dgrafxCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now