0

在更改文件大小并将其存储到服务器之前,我需要遍历路径名和图像名称列表并验证文件是否存在并且是 jpg/png。

我想用这个:

   <cffile result="upload" action="upload" accept="image/jpeg, image/png" destination="#tempDirectory#" nameconflict="overwrite" />
    <cfset testFilePath = tempDirectory & upload.serverFile>
    <cfimage name="tempFile" action="read" source="#testFilePath#" />
    <cfif NOT isImageFile( testFilePath ) >
        <cfset fileDelete( testFilePath ) />
        <cfthrow type="FileNotFound" message="#tx_settings_icons_error_img#" />
    <cfelseif NOT listfindnocase(allow, upload.serverfileext) >
        <cfset fileDelete( testFilePath ) />
        <cfthrow type="FileNotFound" message="#tx_settings_icons_error_file#" />
    </cfif>

但我的问题是,我不知道如何从路径上传文件

 http://www.some.com/folder/image.jpg

问题
我可以只read图像,执行我的验证然后存储到磁盘还是我需要先上传图像。我将不得不遍历一个包含 500 个图像的列表,并且正在阅读cffile action="read"不应该与大文件一起使用。isImage检查图像文件的正确类型和文件扩展名的替代方法是什么?

4

2 回答 2

5

我通常cfhttp用来读取图像并验证我是否拥有它,然后转换为有效cfimage对象并进行操作。你可以在这个问题的答案中看到我的过程。

于 2012-08-09T22:14:24.923 回答
2

使用 cfimage 从 URL 读取文件。将源设置为该 URL。然后,您可以将其写入本地磁盘。

代码示例:

<cfset imageData = ImageRead("http://tutorial28.learncf.com/img/bgHead.png") />
<cfimage action="write" source="#imageData#" destination="#expandPath('test.png')#" />
于 2012-08-09T21:56:55.927 回答