coldfusion – <cffile action=”Read”> not getting the desired up-load loaction – Education Career Blog

I am using CF-8,windows-XP and IE 5.5.

I am using simple tag namely . but the output i am getting is pure gibberih along witht the text of the file(word document)

upld.cfm

   <cffile action="read" file="C:\ColdFusion8\wwwroot\Proj\updl\fileDisk\SOL.doc" variable="fileDisk"   >
          <cfoutput>#fileDisk#
         </cfoutput>

<cfoutput>
<form  name="upload" method="post" action="actionUpld.cfm?form_Num=#form_Num#" enctype="multipart/form-data">

<input name="uplForm" id="uplForm" type="file" >
<input type="submit" name="submitUpld" value="Save" onclick="" >

</form>
</cfoutput>

actionUpld.cfm

<cftry>
<cfscript>         
             newUPL = CreateCFC('cfcs.projDB');     
             newUPL.Implementation_Num =    url.form_Num;
             newUPL.uplForm = form.uplForm;
             newUPL.putUPL();        
</cfscript>
 <cfcatch type="any" >
        <cfoutput >
            <hr>
             <h4>Other Error: #cfcatch.Type#</h4>
                <li><b>Message:</b> #cfcatch.Message#
                <li><b>Detail:</b> #cfcatch.Detail#
                <li><b>Error Code:</b> #cfcatch.ErrorCode#
           </cfoutput>
       </cfcatch>
</cftry>
<cflocation url="upld.cfm??form_Num=#form_Num#" >

How best to use the cffile to output the file ?

Also when i look at the DB, i am getting the file name as

"C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\qeq344.tmp"
How to correct it?

Is there any better way.

,

Also when i look at the DB, i am
getting the file name as C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\qeq344.tmp

That is a temporary file name assigned to newly uploaded files. On your action page, you need to use cffile action=”upload” … to move that temporary file to the desired location. That will populate a structure called CFFILE with details about the uploaded file, such as CFFILE.serverFile and CFFILE.serverDirectory. (Or use the “result” attribute to output the details to whatever structure name you choose.)

How best to use the cffile to output
the file ?

You cannot display binary files (like *.doc) with cfoutput. To display/download such files in a browser use cfcontent

Leave a Comment