lulu50
asked on
Loop thru a multiple files
Hi,
I need to loop thru the uploaded files and insert them into the database as an objects.
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif IsDefined('FORM.File_ + counter')>
INSERT INTO Impact_Log_Files (UploadedFile)
VALUES (
<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(FOR M.File_ + counter)#">
)
</cfif>
</cfloop>
</cfquery>
I need to loop thru the uploaded files and insert them into the database as an objects.
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource='#strDSN#' username='#strUID#' password='#strPWD#'>
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif IsDefined('FORM.File_ + counter')>
INSERT INTO Impact_Log_Files (UploadedFile)
VALUES (
<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(FOR
)
</cfif>
</cfloop>
</cfquery>
ASKER
dgrafx,
can you please tell me how I am going to put it in <cfqueryparam
<cfqueryparam cfsqltype="cf_sql_blob"
value='#FileReadBinary(for m['file_' & counter])#'>,
I tried both ways but it did not work
the error:
The tag must be nested inside a cfquery tag.
can you please tell me how I am going to put it in <cfqueryparam
<cfqueryparam cfsqltype="cf_sql_blob"
value='#FileReadBinary(for
I tried both ways but it did not work
the error:
The tag must be nested inside a cfquery tag.
you need to keep the code within your cfquery tag like you originally showed.
i simply supplied the meat of the problem.
see below
========================== ========== ===
First a note:
I advise that you get organized with single vs double quotes in the code you write.
Don't start off using single quotes (') and change to double quotes (") midstream or some variation of that.
Look at the code you first posted vs what I'm posting here.
Also, notice how you changed the double quotes I used in the code I provided for you to single - that won't work when you are using single quotes to set the value.
See this: <cfset xyz='don't use quotes like this'>
Do you see why this won't work?
It should be <cfset xyz="don't use quotes like this">
========================== ========== ===
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">
Set Nocount On;
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif StructKeyExists(form,"file _" & counter)>
INSERT INTO Impact_Log_Files
(UploadedFile)
VALUES
(<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(for m['file_' & counter])#">)
</cfif>
</cfloop>
</cfquery>
good luck ...
i simply supplied the meat of the problem.
see below
==========================
First a note:
I advise that you get organized with single vs double quotes in the code you write.
Don't start off using single quotes (') and change to double quotes (") midstream or some variation of that.
Look at the code you first posted vs what I'm posting here.
Also, notice how you changed the double quotes I used in the code I provided for you to single - that won't work when you are using single quotes to set the value.
See this: <cfset xyz='don't use quotes like this'>
Do you see why this won't work?
It should be <cfset xyz="don't use quotes like this">
==========================
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">
Set Nocount On;
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif StructKeyExists(form,"file
INSERT INTO Impact_Log_Files
(UploadedFile)
VALUES
(<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(for
</cfif>
</cfloop>
</cfquery>
good luck ...
ASKER
in SQL the datatype for my field is this :
UploadedFile varbinary(MAX) Checked
Is this correct?
UploadedFile varbinary(MAX) Checked
Is this correct?
Yes
Also
In ColdFusion Administrator I believe you need to enable binary large object retrieval (BLOB)
Thats in Advanced Settings when viewing the datasource.
If you are on hosted server where you don't have access to CF Administrator then ask your host about this if you are having issues.
NOTE: don't worry about this if you are not having issues!
Also
In ColdFusion Administrator I believe you need to enable binary large object retrieval (BLOB)
Thats in Advanced Settings when viewing the datasource.
If you are on hosted server where you don't have access to CF Administrator then ask your host about this if you are having issues.
NOTE: don't worry about this if you are not having issues!
ASKER
dgrafx,
my error now says that:
File '' does not exist.
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">
Set Nocount On;
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif StructKeyExists(form,"file _" & counter)>
INSERT INTO Impact_Log_Files
(UploadedFile)
VALUES
(<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(for m['file_' & counter])#">)
)
</cfif>
</cfloop>
</cfquery>
my error now says that:
File '' does not exist.
<cfset maxFiles = 3>
<cfquery name = "QLogFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">
Set Nocount On;
<cfloop from="1" to="#maxFiles#" index="counter">
<cfif StructKeyExists(form,"file
INSERT INTO Impact_Log_Files
(UploadedFile)
VALUES
(<cfqueryparam cfsqltype="cf_sql_blob"
value="#FileReadBinary(for
)
</cfif>
</cfloop>
</cfquery>
ASKER
do I have to upload to the server first
or
I can just save it directly?
or
I can just save it directly?
ASKER
hmmm
I just did this
<cfdump var="#form.file_1#">
just to see the value that I am passing
and it says it is an empty string
I just did this
<cfdump var="#form.file_1#">
just to see the value that I am passing
and it says it is an empty string
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dgrafx,
Thank you so much for the example. Just one more thing before I close this question.
How can I call the binary file from my database after it got saved in the database. so, the user can download or save the file?
I can't thank you enough for all your help.
Thank you so much for the example. Just one more thing before I close this question.
How can I call the binary file from my database after it got saved in the database. so, the user can download or save the file?
I can't thank you enough for all your help.
ok so your files are in the db
below i'm using download.png as a name for your image
for queryname.UploadedFile below - use your own query name
<cfheader
name="content-disposition"
value="inline; filename=download.png"
/>
<cfcontent
type="image/*"
variable="#queryname.Uploa dedFile#"
/>
==============
I have to ask though - WHY are you storing images as blobs in the DB?
Why not just save the image to disk with a reference to the image in the DB?
below i'm using download.png as a name for your image
for queryname.UploadedFile below - use your own query name
<cfheader
name="content-disposition"
value="inline; filename=download.png"
/>
<cfcontent
type="image/*"
variable="#queryname.Uploa
/>
==============
I have to ask though - WHY are you storing images as blobs in the DB?
Why not just save the image to disk with a reference to the image in the DB?
ASKER
company requirement -> security issues.
Thank you again,
lulu
Thank you again,
lulu
ASKER
Thank you
ok so you'll need to delete the files after uploading them - right?
ASKER
dgrafx
are you still there
I thought I got it to work but it's not
are you still there
I thought I got it to work but it's not
ASKER
I'll open a new question for it
what's not working?
post a link here to the new link
INSERT INTO Impact_Log_Files
(UploadedFile)
VALUES
('#form["file_" & counter]#')
</cfif>
or use
('#FileReadBinary(form["fi
if reading binary is what you want