Coldfusion,使用 GetHttpRequestData 来存储和处理文件

发布于 2024-09-11 20:14:23 字数 542 浏览 4 评论 0原文

我有一个 JQUERY 文件上传插件,允许用户将文件上传到 Coldfusion 服务器。该插件将文件提交到服务器的方式要求我使用 GetHttpRequestData() 来获取文件内容。这是到目前为止我在处理文件数据方面所拥有的:

<cfparam name="URL.qqfile" type="string">
<cfset x = GetHttpRequestData()>
<cffile action="write" output="#x.content#" file="c:\temp\#URL.qqfile#">

这有效,这很好,但我似乎无法将其带到下一步。

接下来我想要发生的是: A. 确定文件的扩展名。 B. 如果它是我的应用程序定义的可接受的扩展(JPG、PNG、PDF、DOC、DOCX 等),请将其上传到服务器上的正确目录。然后删除上面的临时文件 C. 如果上传的文件是图像,则使用 CFIMAGE 制作缩略图

如何通过步骤 AC 解决 GetHttpRequestData 问题?

谢谢

I have a JQUERY file upload plug-in which allows users to upload files to the Coldfusion server. The plugin submits the files to the server in a way that requires me to use GetHttpRequestData() for the files contents. Here's what I have so far in terms of handling the file data:

<cfparam name="URL.qqfile" type="string">
<cfset x = GetHttpRequestData()>
<cffile action="write" output="#x.content#" file="c:\temp\#URL.qqfile#">

This works, which is nice, but I can't seem to take this to the next step.

What I want to happen next is:
A. Determine the file's extension.
B. If it is an accepted ext defined by my app, (JPG,PNG,PDF, DOC, DOCX, etc...) upload it to the correct directory on the server. Then delete the temp file above
C. Use CFIMAGE to make a thumbnail if the file uploaded was an Image

How can I take the above through steps A-C with the GetHttpRequestData problem?

Thanks

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

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

发布评论

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

评论(1

无人问我粥可暖 2024-09-18 20:14:23

一些提示:

  • 通过 查看 GetHttpRequestData() 的结果结构。
  • 通过访问此结构来提取必要的标头。 Content-Type 标头通常包含您想了解的内容。您可以使用列表函数 (即 ListLen()ListFirst()ListLast()ListRest() 以及适当的分隔符)轻松解析字符串。
  • 始终使用 StructKeyExists() 来防止丢失结构部分。永远不要认为此结构中“通常”出现的任何内容都是理所当然的。
  • 不要盲目信任文件扩展名或 Content-Type 标头。还要查看上传文件的前几个字节,并将它们与白名单进行比较,以确认文件类型。
  • 查看
  • (可选)执行驱动器空间测试< /a> 评估上传的数据是否不会阻塞服务器,或以其他适合您的方式强制执行限制。
  • 通读 的文档。用它来制作缩略图不会那么困难。

A few tips:

  • Have a look at the result structure of GetHttpRequestData() via <cfdump>.
  • Pull out the necessary headers by accessing this struct. The Content-Type header usually contains the stuff you want to know. You can use the List functions (i.e. ListLen(), ListFirst(), ListLast(), ListRest() with appropriate delimiter chars) to easily parse the string.
  • Always use StructKeyExists() to safeguard against missing struct parts. Never take for granted anything that "typically" seems to be in this struct.
  • Don't blindly trust file extensions or the Content-Type header. Also look into the first few bytes of the uploaded file and compare them against a white list to confirm the file type.
  • Have a look at <cffile action="upload">.
  • Optionally, perfom a drive space test to assess if the uploaded data does not clog the server, or enforce limits in another way that suits you.
  • Read through the documentation of <cfimage>. It can't be that hard to use it to make thumbnails.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文