2010-02-09 4 views

답변

10

사용자 정의 함수로 쉽게 추상화 할 수 있습니다.

<cffunction name="fileuploader"> 
    <cfargument name="formfield" required="yes" hint="form field that contains the uploaded file"> 
    <cfargument name="dest" required="yes" hint="folder to save file. relative to web root"> 
    <cfargument name="conflict" required="no" type="string" default="MakeUnique"> 
    <cfargument name="mimeTypesList" required="no" type="string" hint="mime types allowed to be uploaded" default="image/jpg,image/jpeg,image/gif,image/png,application/pdf,application/excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,image/pjpeg"> 

    <cffile action="upload" fileField="#arguments.formField#" destination="#arguments.dest#" accept="#arguments.mimeTypesList#" nameConflict="#arguments.conflict#"> 

    <cfreturn cffile> 
</cffunction> 

그리고는 CFScript의에서 사용 :

<cfscript> 
    // NOTE: because of how cffile works, put the form field with the file in quotes. 
    result = fileUploader("FORM.myfield", myDestPath); 
    WriteOutput(result.fileWasSaved); 
</cfscript> 

참고 : 나는 당신이 어도비 길 아래에이 기능을 포함하지 경우이 기능의 이름을 변경하는 방법을 매우 조심해야합니다.

+0

그건 정확히 내가 과거에 한 일이야, 나는 단지 내가 그것을 피할 수 있었으면 좋겠다. 10시에. 아마도 –

+0

새로운 기능이 추가되었다. 위의 편집 된 질문에서 링크를 참조하라. –

1

아니에 추가되었습니다 있지만 요구되고있다.

+0

추가 된 파일 기능의 수를 고려하면 이상한 업로드가 포함되지 않았습니다. –

2

CF를 추가했지만 CF가 CFSCRIPT의 파일 업로드를 지원하는지 확실하지 않습니다. 나는 잠시 동안 FileUpload()를 사용 해왔다. 내 MVC 프레임 워크에서 함수가 아니며 def가 CF 9.01에 고유 한 것으로 보인다는 것을 확인했습니다.

그러나 빌더 2는 그것을 좋아하지 않는 것도 나는 CF 9 문서에 대한 참조를 찾을 수 있지만 작업을 수행하고 그것은 내가 사용

예 tho를 확인하지 않은, Ralio 지속 어도비 ColdFusion에서 9.01 부분이다 :

fileUpload(getTempDirectory(),"ImageFile","","makeUnique"); 
관련 문제