ColdFusionで簡易ファイルブラウザ
元記事はこちらです。
■Application.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <cfsetting enableCFoutputOnly="yes"> <cfapplication name="#hash( getCurrentTemplatePath() )#" sessionmanagement="yes" sessiontimeout=#CreateTimeSpan(0, 0, 10, 0)# > <cfparam name="session.key" default=""> <cfset request.key = "123"> <!---=============================== path OSによるパスの違い Windows:\ Windows以外:/ ================================---> <cffunction name="getPath" access="public" returnType="string" output="no" hint="パスを取得(Windowsは\,それ以外は/)"> <cfset var path=""> <cfif server.os.name contains "Windows"> <cfset path = "\"> <cfelse> <cfset path = "/"> </cfif> <cfreturn path> </cffunction>
■index.cfm
<cfprocessingdirective pageEncoding = "UTF-8"> <!---///////////////////////////////////////////////////////////////// 簡易ファイルブラウザ //////////////////////////////////////////////////////////////////---> <cfparam name="url.key" default=""> <cfparam name="form.path" default="#GetDirectoryFromPath(getCurrentTemplatePath())#"> <cfparam name="form.name" default=""> <cfparam name="form.chk" default=""> <cfparam name="form.type" default=""> <cfparam name="form.create_type" default=""> <cfif (form.create_type neq "")> <cfset dttm = dateformat(now(), "yyyymmdd") & timeformat(now(), "HHmmss") & right("00#timeformat(now(), 'l')#", 3)> <cfif (form.create_type eq "Dir")> <cfdirectory action="create" directory="#form.path##dttm#" mode="707"> </cfif> <cfif (form.create_type eq "file")> <cffile action = "write" file = "#form.path##dttm#.txt" output = "dummy" mode = "707"> </cfif> </cfif> <cfif (url.key neq "")> <cfset session.key = url.key> </cfif> <cfif (form.chk neq "")> <cfif (form.type eq "Dir")> <cfdirectory name="qDir" directory="#form.path##form.name#"> <cfif (qDir.recordCount eq 0)> <cfdirectory action="delete" directory="#form.path##form.name#"> </cfif> </cfif> <cfif (form.type eq "file")> <cffile action="delete" file="#form.path##form.name#"> </cfif> </cfif> <!--- 画面表示 ---> <cfset dsp_list(form.path)> <!---================================================================= 画面表示 ==================================================================---> <cffunction name="dsp_list" returntype="void" output="yes"> <cfargument name="path" type="string" required="yes"> <cfset var local = structNew()> <cfset local.dir = arguments.path> <cfdirectory name="local.qDir" directory="#local.dir#" sort="type,name"> <cfoutput> <table border="1"> <tr> <td> #local.dir# </td> <form action="index.cfm" method="post"> <input type="hidden" name="path" value="#ListDeleteAt(local.dir, ListLen(local.dir,'#getPath()#'),'#getPath()#')##getPath()#"> <td><input type="submit" value="up"></td> </form> <form action="index.cfm" method="post"> <input type="hidden" name="path" value="#local.dir#"> <input type="hidden" name="create_type" value="Dir"> <td><input type="submit" value="createDir"></td> </form> <form action="index.cfm" method="post"> <input type="hidden" name="path" value="#local.dir#"> <input type="hidden" name="create_type" value="file"> <td><input type="submit" value="createFile"></td> </form> </tr> </table> <table border="1"> <tr> <td>check</td> <td>type</td> <td>name</td> <cfif (session.key eq request.key)> <td> </td> </cfif> <td> </td> </tr> <cfloop query="local.qDir"> <tr> <form name="frm_#local.qDir.currentRow#" action="index.cfm" method="post"> <input type="hidden" name="path" value="#local.dir#"> <input type="hidden" name="name" value="#local.qDir.name#"> <input type="hidden" name="type" value="#local.qDir.type#"> <td> <input type="checkbox" name="chk" value="1"> </td> <td>#local.qDir.type#</td> <td>#local.qDir.name#</td> <cfif (session.key eq request.key)> <td> <input type="submit" value="del"> </td> </cfif> </form> <cfif (local.qDir.type eq "Dir")> <form name="frm_down#local.qDir.currentRow#" action="index.cfm" method="post"> <input type="hidden" name="path" value="#local.dir##local.qDir.name##getPath()#"> <td> <input type="submit" value="down"> </td> </form> <cfelse> <td> </td> </cfif> </tr> </cfloop> </table> </cfoutput> </cffunction>