ColdFusion: No data was received in the uploaded file

馋奶兔 提交于 2019-12-24 07:15:26

问题


My error report told me that an error has occurred when an user tried uploading an empty file to my server (don't ask why the user did that - I don't know) and now I want to catch that exception which said "No data was received in the uploaded file". I wonder if there is a better way than putting a <CFTRY> around the <CFFILE action="upload"> like this:

<CFTRY>
  <CFFILE action="upload" destination="#expandpath("upload")#" filefield="form.file" nameconflict="makeunique" />
  <CFCATCH>
    <!--- handle that error --->
  </CFCATCH>
</CFTRY>

回答1:


Try/Catch is the way I usually handle it.

<cftry>
    <cffile action="upload" ...>

    <cfcatch type="any">
        <cfif Find("Saving empty (zero-length) files is prohibited", CFCatch.Detail) GT 0>

            <!--- Create a zero length file on disk and continue processing as usual --->
            <cffile action="write" file="..." output="">
        <cfelse>
            <cfrethrow>
        </cfif>
    </cfcatch>
</cftry>


来源:https://stackoverflow.com/questions/13249065/coldfusion-no-data-was-received-in-the-uploaded-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!