ColdFusion server file with apostrophe character

送分小仙女□ 提交于 2019-12-11 05:08:25

问题


When I try to upload a file with apostrophe, I get the error:

    Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

if the file name is test's.pdf, I get the error. But if I change the name to test.pdf, there is no error.

Does anyone know why?

Thanks


回答1:


I had a similar situation where I was dynamically creating filenames for pages that created excel files from query results. The approach I took was to create a function that replaced all the bad characters with something. Here is part of that function.

<cfargument name="replacementString" required="no" default=" ">
<cfscript>
var inValidFileNameCharacters = "[/\\*'?[\]:><""|]";
return reReplace (arguments.fileNameIn, inValidFileNameCharacters, arguments.replacementString, "all");
</cfscript>

You might want to consider an opposite approach. Instead of declaring invalid characters and replacing them, declare valid ones and replace anything that is not in the list of valid characters.

I suggest making this a function that's available on all appropriate pages. How you do that depends on your situation.




回答2:


My guess is that the apostrophe is one of those multi-character apostrophes that Microsoft Word often uses. A character like that may not be a valid character for your OS file system.

You may want to re-code the system to use a temporary file on upload and then rename it to a valid file name after the upload is successful.

Here's some basic trouble shooting info.

Wrap your code in a try/catch block and dump the full error to the page output. Examples of using try/catch/dump below. The examples below force an error by dividing by zero.

For tag based cfml:

<cftry>
    <cfset offendingCode = 1 / 0>

    <cfcatch type="any">
        <cfdump var="#cfcatch#" label="cfcatch">
    </cfcatch>
</cftry>

For cfscript cfml:

<cfscript>
    try {
        offendingCode = 1 / 0;
    } catch (any e) {
        writeDump(var=e, label="Exception");
    }
</cfscript>


来源:https://stackoverflow.com/questions/46436669/coldfusion-server-file-with-apostrophe-character

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