2012-08-09 67 views
0

我需要遍历路径名和图像名称列表,并验证该文件是否存在,并且是jpg/png,然后才能更改它的大小并将其存储到服务器。我可以使用Coldfusions cffile action =“upload”与图像destionation url吗?

我想用这样的:

<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和文件扩展名?

感谢您的帮助!

回答

5

我一般使用cfhttp读取图像,并验证我拥有了它,然后将其转换为有效的cfimage对象,做我的操作即可。你可以在this question的回答中看到我的过程。

+0

谢谢。这看起来不错。 – frequent 2012-08-10 07:14:24

2

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

代码示例:

<cfset imageData = ImageRead("http://tutorial28.learncf.com/img/bgHead.png") /> 
<cfimage action="write" source="#imageData#" destination="#expandPath('test.png')#" /> 
+0

好的。感谢提示! – frequent 2012-08-09 22:03:50

相关问题