I need to loop over a list of pathnames and image names and verify that the file exists and is a jpg/png, before changing it's size and storing it to the server.
I want to use this:
<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>
But my problem is, I don't know how to upload a file from a path like
http://www.some.com/folder/image.jpg
Question:
Can I just read
the image, perform my validation and then store to disk or do I need to upload the image first. I will have to loop through a list of 500 images and am reading cffile action="read"
shouldn't be used with large files. What would be an alternative to check image files for correct type, isImage
and file extension?
I generally use cfhttp
to read the image and verify that I have it, then convert to a valid cfimage
object and do my manipulations then. You can see my process in the answer to this question.