Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problems with cffile

Contributor ,
Dec 03, 2007 Dec 03, 2007
I am trying to write code that will upload a file and add the name of the file uploaded to my DB. I have it on a page that serves 2 functions.

1. add a new record
2. edit an existing record

I am attaching my code here:

I have 3 issues happening here that I don't understand.

1. right now it uploads my picture but doesn't save any information into the body section of the database and doesn't place the image name into the database.

2. on the edit page where I am using the input for the file, I want it to state the file loaded in the DB under it when you go to edit a record.

3. I also get an error when I try and use the accept="image/gif, image/jpeg" portion of the code from the action scrpit.

Can anyone help me? I am stumped and I need to get this working.

Thank you.

Phoenix

2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 07, 2007 Dec 07, 2007
Great!

now, for the file deletion - i can't really see anything obviously wrong
with it...
one thing i would try is move the cffile action=delete to before the
delete query...
and you can add some debugging to it to try and see what is happening there:

1) add <cfoutput>#pathtofile#</cfoutput> after setting that var to see
what it is being set to
2) put the cffile code inside a cftry/cfcatch block and cfdump the
#cfcatch# variable on error:
<cftry>
...your cffile delete code
<cfcatch type="...
Translate
Contributor ,
Dec 07, 2007 Dec 07, 2007
IT WORKS!!!!!!!!! Thank you!!!

One last question if you don't mind, I have a delete function. it deletes the record, but it doesn't delete the image on the server, what am I missing on this?

<cfelseif IsDefined("Form.feat_Delete")>
<cfquery name="getFileName" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
SELECT MYFile
FROM feature
WHERE id = #form.id#
</cfquery>

<cfif getFileName.recordCount GT 0>
<!--- delete the record --->
<cfquery name="deleteRecord" dataSource="#sitedatasource#" maxRows=1>
DELETE
FROM feature
WHERE id = #form.id#
</cfquery>
<cfset pathToFile = "c:\websites\x9vdzd\img\feature\#getFileName.MYFile#">
<cfif FileExists(pathToFile)>
<cffile action="delete" file="#pathToFile#">
</cfif>
</cfif>
<cflocation url="feature-manager.cfm">

Is it something simple I missed?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2007 Dec 07, 2007
Great!

now, for the file deletion - i can't really see anything obviously wrong
with it...
one thing i would try is move the cffile action=delete to before the
delete query...
and you can add some debugging to it to try and see what is happening there:

1) add <cfoutput>#pathtofile#</cfoutput> after setting that var to see
what it is being set to
2) put the cffile code inside a cftry/cfcatch block and cfdump the
#cfcatch# variable on error:
<cftry>
...your cffile delete code
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>

on a related subject:
if the delete code is on the same action page of the same form as your
insert/update form, then you do not really need your getFileName query,
since your form already holds the file name in the hidden oldimage field...

---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 07, 2007 Dec 07, 2007
ok, that works now 2. I moved the delete function before the delete query and now it is working fine.

Thank you for all your help! I owe you big time.

Sorry it was such a mess fixing this up. Now that I am on a cf 8 server, things should work better.

Just going to fix the delete with cfquryparam and I am done with it.

Thanks again!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 07, 2007 Dec 07, 2007
LATEST
no problem! glad i could help!
cf8 is amazing - i am loving it more and more every day!

---
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources