将文件保存到 Coldfusion 中的服务器,存储在 CF 临时目录中而不是指定的目的地

发布于 2024-12-19 11:26:58 字数 1155 浏览 0 评论 0原文

我在带有 Apache 和 MySQL 的 Ubuntu Linux 服务器上使用 Coldfusion 8。上传的任何文件都会存储在 Coldfusion 临时目录中: [/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] 我显然希望将其存储到 /var/www/cfm3/images [其中 #destination 的值#.我已经尝试过该网站提供的其他解决方案,但他们倾向于分叉到其他尚未解决我的解决方案的解决方案。下面是我的代码的示例。

    <cfset destination = expandPath("images") />
<cfif not directoryExists(destination)>
    <cfdirectory action="create" directory="#destination#">
</cfif>
<cfloop from="1" to="#num_users#" index="i">
    <cfoutput>User #i# Photo Upload : 
        <cfif isDefined("#i#")>
            <cffile action="upload"
                    fileField="#i#"
                    accept="image/jpeg, image/gif, image/png" 
                    destination="#destination#"
                    nameConflict="makeUnique"
                    mode = 777>
            <cfdump var="#upload#">
            <p>Thank you, your file has been uploaded.</p>
        </cfif>
        <input type="file" name="#i#" /><br />
    </cfoutput>
</cfloop>

任何帮助将不胜感激。 :D

I'm using Coldfusion 8 on an Ubuntu Linux server with Apache and MySQL. Any file uploaded get stored in the Coldfusion temp directory:
[/opt/coldfusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp17260.tmp] I obviously want it to be stored in to /var/www/cfm3/images [which the value of #destination#. I have tried other solutions provided by this site but they tend to fork off to other solutions that have not solved my solution. Below is the an example of my code.

    <cfset destination = expandPath("images") />
<cfif not directoryExists(destination)>
    <cfdirectory action="create" directory="#destination#">
</cfif>
<cfloop from="1" to="#num_users#" index="i">
    <cfoutput>User #i# Photo Upload : 
        <cfif isDefined("#i#")>
            <cffile action="upload"
                    fileField="#i#"
                    accept="image/jpeg, image/gif, image/png" 
                    destination="#destination#"
                    nameConflict="makeUnique"
                    mode = 777>
            <cfdump var="#upload#">
            <p>Thank you, your file has been uploaded.</p>
        </cfif>
        <input type="file" name="#i#" /><br />
    </cfoutput>
</cfloop>

Any help would be greatly appreciated. :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别低头,皇冠会掉 2024-12-26 11:26:58

我有预感问题在于您如何创建 destination 变量,假设它是正确的(即使在创建之后),然后立即将其传递给 CFFILE。

请参阅这个类似的问题(和解决方案):

将文件保存到ColdFusion中的服务器

在上面链接的这个问题中,回答者指出:

目的地必须是完整路径,否则它将被发送到
目录相对于 Cold Fusion 的临时目录 [原文如此]。

这与您所经历的行为非常相似 - 您希望该文件位于特定文件夹中,但它最终不会出现错误,而是位于“temp”目录中。

我会在模板中获得一些跟踪/调试信息,特别是在将目标变量的值提供给 CFFILE 之前。有些东西与您的描述不太相符,很可能是一条错误的路径,或者可能是它周围的权限。

I have a hunch the problem lies within how you are creating the destination variable, assuming it is correct (even after a create), and then immediately passing it to CFFILE.

Refer to this similar question (and solution):

Saving File to Server in ColdFusion

In this question linked above, the answerer notes that:

The destination has to be a full path, otherwise it gets sent to a
directory relative to the temp directory of Cold Fusion [sic].

This is very similar behavior to what you are experiencing--you want the file in a specific folder, but rather than error out, it ultimately lands in the "temp" dir.

I'd get some trace/debugging info in your template, specifically surrounding the value of the destination variable, prior to it being fed to CFFILE. Something doesn't quite gel with your description, and it could very well be a faulty path, or perhaps permissions surrounding it.

涙—继续流 2024-12-26 11:26:58

您是否收到类似于“上传未定义”的错误?如果是这样,请更改此行:

<cfdump var="#upload#">

改为:

<cfdump var="#cffile#">

如果您没有收到该错误...您会得到什么输出?

编辑

另外,我个人不会将您的表单字段命名为简单的数字。尝试更改为:

<cfloop from="1" to="#num_users#" index="i">
    <cfoutput>User #i# Photo Upload : 
        <cfif isDefined("user#i#")>
            <cffile action="upload"
                    fileField="user#i#"
                    accept="image/jpeg, image/gif, image/png" 
                    destination="#destination#"
                    nameConflict="makeUnique"
                    mode = 777>
            <cfdump var="#cffile#">
            <p>Thank you, your file has been uploaded.</p>
        </cfif>
        <input type="file" name="user#i#" /><br />
    </cfoutput>
</cfloop>

注意字段名称之前的“用户”前缀。

Are you getting an error similar to "upload not defined"? If so, change this line:

<cfdump var="#upload#">

To this:

<cfdump var="#cffile#">

If you aren't getting that error.... what output are you getting?

edit

Also, personally I wouldn't name your form fields as simple numbers. Try changing to this:

<cfloop from="1" to="#num_users#" index="i">
    <cfoutput>User #i# Photo Upload : 
        <cfif isDefined("user#i#")>
            <cffile action="upload"
                    fileField="user#i#"
                    accept="image/jpeg, image/gif, image/png" 
                    destination="#destination#"
                    nameConflict="makeUnique"
                    mode = 777>
            <cfdump var="#cffile#">
            <p>Thank you, your file has been uploaded.</p>
        </cfif>
        <input type="file" name="user#i#" /><br />
    </cfoutput>
</cfloop>

Note the "user" prefix before your field names.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文