4 Replies Latest reply on Jul 18, 2006 9:21 AM by LaoD

    Using CFFILE Upload to Modify an Existing File

    cfgators
      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>
        • 1. Re: Using CFFILE Upload to Modify an Existing File
          dpretlor Level 1
          on the destination attribute try adding the name of the file at the end of the directory path.
          • 2. Re: Using CFFILE Upload to Modify an Existing File
            cfgators Level 1
            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
            • 3. Re: Using CFFILE Upload to Modify an Existing File
              cfgators Level 1
              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>
              • 4. Re: Using CFFILE Upload to Modify an Existing File
                LaoD
                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">