Question : Display title defined by user

Not sure if this is possible but the people that upload the files in the way described in the code will want to type a title instead of just having the file name display.  Any help is appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
<cfset application.documentsDirectory = "C:\Inetpub\wwwroot\Intranet\uploadfiles\">
<cfset application.documentsDirUrl = "http://localhost/Intranet/uploadfiles/">

<!--- Get Directory Contents --->
<cfdirectory directory="#application.documentsDirectory#" name="documentsDirectory" sort="size ASC, name DESC, datelastmodified">

<!--- This checks for the existence of at least 1 file within the directory and if true loops through the list of files and outputs each filename with a linking url. There are many more options available for reading the type of file - it's size etc... using the cfdirectory and cffile tags but you'll have to look in the reference pdf for more information --->
<cfif IsDefined("documentsDirectory") and documentsDirectory.RecordCount gt 0>
<cfloop query="documentsDirectory">
   <cfif documentsDirectory.size lt 1025>
<cfset document_size = documentsDirectory.size>
<cfset size_type = "bytes">
<cfelseif documentsDirectory.size gt 1024 and documentsDirectory.size lt 1048577>
<cfset document_size = documentsDirectory.size/1024>
<cfset size_type = "Kb">
   <cfelse>
<cfset document_size = documentsDirectory.size/1048576>
<cfset size_type = "Mb">
    </cfif>
<cfoutput>
<a href="#application.documentsDirUrl#/#documentsDirectory.name#">#documentsDirectory.name#</a> #NumberFormat(document_size,"___,___")# #size_type#</cfoutput><br />
</cfloop>
</cfif>

Answer : Display title defined by user

Ok here goes a small example

First we need a table called files
with two columns file and title  both varchar.


A form page to to upload a file and enter title for that file .

Form page :
<form name="uploadfrm" method = "post" action ="action.cfm" enctype="multipart/form-data">

<input type ="file"> name="uploadfile">

<input type="text" name="Title">

<input type="submit" name="submit" value="submit">

</form>



An action page which takes that uploaded file and uploads it to a upload folder and inserts in to table files the filename and the title of that file.


Action page :

ACTION.CFM

<cfif isDefined("Form.uploadfile") and Form.uploadfile neq "">
 <cfset uploadPath = GetDirectoryFromPath(GetBaseTemplatePath()) & "uploads\">
 <cfif not DirectoryExists(uploadPath)>
   <cfdirectory action="create" directory="#uploadPath#">
 </cfif>
 <cffile action="upload" fileField="uploadfile" destination="#uploadPath#" nameConflict="overwrite">
 <cfset filename =  cffile.serverFile >


 <cfquery
              name=""
              datasource="">
              insert into files
              (file,Title)
              Values('#filename #','#form.title#')
         </cfquery>


</cfif>


So when you are looping through files just query the db for that file name and get the title of that file .


Random Solutions  
 
programming4us programming4us