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

Using CFFILE Upload to Modify an Existing File

New Here ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

I am using to following code to modify an existing file on the server, but when I submit the code nothing happens on the server and the file does not get overwritten or modified. Could someone look at my code and see If I am missing anything?

Thanks, cfgator

CODE:

<cfif #FORM.hsmFileName# NEQ '' >
<!--- Modify Small Image files --->
<cffile
action="upload"
filefield="smImageFil"
destination="D:\www_root\qep\web\images\products\"
attributes="Normal"
nameconflict="overwrite">

<cfset oldPathAndName = #FORM.hsmFileName#>
<cfset arrPathAndName = ListToArray(oldPathAndName, '\')>
<cfset fileName = arrPathAndName[ArrayLen(arrPathAndName)]>
<!--- Rename the file to the product number --->
<cfset name1 = "D:\www_root\qep\web\images\products\" & #filename#>
<cfset name2 = "D:\www_root\qep\web\images\products\" & #form.prod_number# & "_" & "sm" & "." & "JPG">
<cffile action="rename"
source = "#name1#"
destination = "#name2#"
attributes = "Normal">
</cfif>
TOPICS
Advanced techniques

Views

251

Translate

Translate

Report

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
Explorer ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

on the destination attribute try adding the name of the file at the end of the directory path.

Votes

Translate

Translate

Report

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
New Here ,
Jul 13, 2006 Jul 13, 2006

Copy link to clipboard

Copied

dpretlor,

How would I use the destination attribute to place the name of the file when there will be differnet files being modified and added when using this code?

cfgator

Votes

Translate

Translate

Report

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
New Here ,
Jul 18, 2006 Jul 18, 2006

Copy link to clipboard

Copied

Let me add my form and see if this explains why I am not able to modify a file on the server?

<form name="admin_products" action="index.cfm?fuseaction=dsp_admin_products&subaction=mod&processAction=submitMod" method="post" enctype="multipart/form-data" >

<table>
<!--- Small Product Image File --->
<tr>
<td>
Small Product Image <font color="red"><b>*</b></font> : </td>
<td>
<input class="text" type="File" name="smImageFil" value="Browse..." size="30" tabindex="9" onBlur="return setValue(this, hsmFileName);">
<input type="hidden" name="hsmFileName" value=""> </td>
</tr>

<tr>
<div align="center">
<input type="Submit" name="submit" value=" Modify " tabindex="7">   
<input type="Reset" name="reset" value=" Reset ! " tabindex="8">
<input type="Hidden" name="processAction" value="submitMod">
</div> </td>
</tr>
</table>
</form>

<script language="JavaScript">
function setValue(obj1, obj2)
{
obj2.value = obj1.value;
return true;
}
</script>

Votes

Translate

Translate

Report

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
New Here ,
Jul 18, 2006 Jul 18, 2006

Copy link to clipboard

Copied

LATEST
cfgators,

One thing I see that I would change is where you set your variables. You shouldn't use & signs.

<cfset name1 = "D:\www_root\qep\web\images\products\" & #filename#>
<cfset name2 = "D:\www_root\qep\web\images\products\" & #form.prod_number# & "_" & "sm" & "." & "JPG">

Your name1 ends up being D:\www_root\qep\web\images\products\&filename while your name2 ends up being D:\www_root\qep\web\images\products\&prodnumber&_&sm&.&jpg

If you take out the & signs and the spaces your file name should work and your file should write correctly. Like so...

<cfset name1 = "D:\www_root\qep\web\images\products\#filename#">
<cfset name2 = "D:\www_root\qep\web\images\products\#form.prod_number#_sm.JPG">

Votes

Translate

Translate

Report

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
Documentation