Solved

Display title defined by user

Posted on 2010-08-25
10
374 Views
Last Modified: 2013-12-16
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.
<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>

Open in new window

0
Comment
Question by:JohnMac328
  • 4
  • 4
  • 2
10 Comments
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 33526059
You would have to setup a database that stores user information about a file when they upload the files.
It would be fairly sophisticated for someone with your experience - but I could help you with it.
I'll post some code examples later this evening or in the morning - but for starters build yourself a database table with all the fields you want to capture and I'll help you understand the process later when I can get to it.

I'd give you more now - but I'm getting ready to leave work and I'll be running around for the next couple of hours - then making diner for the family. So either late tonight or in the morning.
0
 

Author Comment

by:JohnMac328
ID: 33526079
No problem, sounds good.

Thanks
0
 
LVL 13

Accepted Solution

by:
srikanthmadishetti earned 250 total points
ID: 33530597
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 .


0
 

Author Comment

by:JohnMac328
ID: 33531282
Ok so far so good.  Now how to display it as a link.  I have the query ShowFile and I put this on the page but it does not show.  I changed file to IntranetFile because file is a reserved word.

<cfquery name="ShowFile" datasource="#datasource#">
Select IntranetFile,Title
FROM Files
</cfquery>
<cfoutput query="ShowFile">
<a href="#IntranetFile##Title#">#IntranetFile#</a>#Title#
</cfoutput>
0
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 33531372
Ok so for starters you'll need to define all the possible fields you will need for managing files in a database structure. I built this query for creating a table the way I manage my files database. It includes fields for things like search keywords, departments, owners, security, text capture so you can search if you have lots of files based on the text within the files themselves etc... You can add or remove whatever you need from this table as you see fit. This just gives you a good starting point and this is a good time to consider the entire project and think about what you'll need to include in the database going forward. I'll be adding a few different posts here but for starters build the database table for storing information about your files. The code below is just an example. I'll explain the thinking in the next post when I put up some example code and I'll give you a few thing to consider before you even start this project. The main things to consider at this point is - how many files are you going to be managing? How many different users, departments, categories, etc... how sensitive are the files... can files be deleted or just tagged so that they don't display.... how are you going to keep backups of the database and file structure... etc... etc...

I'll leave it to you to decide all of these different things but as a project like this grows you'll find you should consider everything at the beginning. Once you start building your database and managing files you don't want to have to start over from scratch every time someone wants to add something new to the system.


/****** Object:  Table [dbo].[fileDB]    Script Date: 08/26/2010 09:21:27 ******/

SET ANSI_NULLS ON

GO



SET QUOTED_IDENTIFIER ON

GO



SET ANSI_PADDING ON

GO



CREATE TABLE [dbo].[fileDB](

	[fileKey] [int] IDENTITY(1,1) NOT NULL,

	[fileLocation] [varchar](255) NULL,

	[fileName] [varchar](255) NULL,

	[fileDescription] [varchar](255) NULL,

	[fileText] [varchar](max) NULL,

	[fileTitle] [varchar](255) NULL,

	[fileCategory] [varchar](2) NULL

	[fileDepartment] [varchar](2) NULL

	[fileOwner] [varchar](2) NULL

	[fileSecurity] [varchar](2) NULL

	[fileKeywords] [varchar](1000) NULL,

	[fileDate] [datetime] NULL,

	[createdDate] [datetime] NULL,

	[createdBy] [varchar](255) NULL,

	[modifiedDate] [datetime] NULL,

	[modifiedBy] [varchar](255) NULL,

	[displayTag] [varchar](1) NULL,

) ON [PRIMARY]



GO



SET ANSI_PADDING OFF

GO

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:JohnMac328
ID: 33531494
Good points to consider and the table fileDB has been created.

0
 
LVL 13

Expert Comment

by:srikanthmadishetti
ID: 33532270
@JohnMac328
Good points by maestropsm but make sure you have the use of that columns . If you don't need much of file management and just need to capture the filenames and titles then you don't need those stuff at all . Like your form does it captures who is uploading do you need keep track of the files deletion etc ,  Does your application have a modified option do you need to capture that modified date too etc .
So  make sure you add columns based on your application , there is no point to have columns which you don't use at all.

and for your question for how to display it as a link
change it like this
<cfoutput query="ShowFile">
<a href="path to uploadfolder / #IntranetFile#">#Title#</a>
</cfoutput>
0
 
LVL 9

Assisted Solution

by:Shaun McNicholas
Shaun McNicholas earned 250 total points
ID: 33532343
Ok here is a page to run for displaying stuff - you'll have to consider how to create an editor for changing things like the title - you could create forms inside the loop and give the user the ability to modify titles right on the same page. That's probably how I would do it. If you want modify more than just the title then I would recommend creating a separate form altogether on another page where you can modify all the fields related to this particular file.

Carefully consider each part of the file - and read all my comments in the code so you understand what's happening.

And please keep in mind I did not create this whole scenario in my own environment I just don't have time right now - plus I would have to change quite a few things because I'm in an all Mac environment. But if you have some errors in the code see if you can figure it out. I may have missed a closing </cfif> or some other tag.

If you have Enable Robust Exception Information turned on in your CF administrator application settings then you should get specific information on errors and be able to debug it.
<cfset application.documentsDirectory = "C:\Inetpub\wwwroot\Intranet\uploadfiles\">

<cfset application.documentsDirUrl = "http://localhost/Intranet/uploadfiles/">



<!--- If this is a subitted edit form for setting the title of a file then the following query will need to be run --->

<cfif IsDefined("modifyTitle") AND IsDefined("DocumentTitle") AND DocumentTitle GT "">

<cfquery name="EditDocumentTitle" datasource="YourDataSourceHere">

    UPDATE fileDB 

    SET fileTitle = <cfqueryparam cfsqltype="cf_sql_varchar" value="#DocumentTitle#">

    WHERE fileKey = <cfqueryparam cfsqltype="cf_sql_integer" value="#fileKey#">

</cfquery>

</cfif>



<!--- This will create a test user if you haven't specified a user in a session variable somewhere else in the system --->

<!--- You can also call the url of this page from your browser and create a UserID by putting the variable after the url like this http://www.somedomain.com/thispage.cfm?UserID=SomeUser --->

<cfif IsDefined("session.UserID")Is False><cfset session.UserID = "TestUser"></cfif>



<!--- If the folder doesn't already exist we need to create it --->

<cfif directoryExists("#application.documentsDirectory#/#session.UserID#") Is False>

<cfdirectory action="create" directory="#application.documentsDirectory#/#session.UserID#">

</cfif>



<!--- Get Directory Contents --->

<cfdirectory directory="#application.documentsDirectory#/#session.UserID#" 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>



<!--- I'm creating a table here so the information displayed looks better in a browser --->

<font face="Verdana, Geneva, sans-serif" size="10pt" color="000000">

<table width="100%" cellpadding="3" cellspacing="0" border="0">

	<thead>

    <tr valign="bottom"><td colspan="8" align="center">You are viewing directory #application.documentsDirectory#/#session.UserID#</td></tr>

    <tr valign="bottom">

        <td>Title</td>

    	<td>File Type</td>

        <td>File Name</td>

        <td>File Size</td>

        <td>Date Created</td>

        <td>Owner</td>

        <td>Last Modified</td>

        <td>Modified By</td>

    </tr>

    </thead>

    <tbody>

            

        <!--- Now output your list of files --->

        <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>

            <cfset document_name=trim(documentsDirectory.name)>

            <cfset document_type=right(document_name,4)>

            <!--- Change the document_icon links to the directory for them on your own server - these are mine --->

            <cfif document_type is ".doc"><cfset document_icon="/images/documents_icons/word.gif"><cfset fileTypeDisplay = "Word">

            <cfelseif document_type is ".xls"><cfset document_icon="/images/documents_icons/excel.gif"><cfset fileTypeDisplay = "Excel">

            <cfelseif document_type is ".pdf"><cfset document_icon="/images/documents_icons/pdf.gif"><cfset fileTypeDisplay = "Adobe PDF">

            <cfelseif document_type is ".txt"><cfset document_icon="/images/documents_icons/txt.gif"><cfset fileTypeDisplay = "Text">

            <cfelse><cfset document_icon="/images/documents_icons/other.gif"><cfset fileTypeDisplay = "Other">

            </cfif>

        <!--- First check your database to see if there is already a file in the database for this file --->

        <cfquery name="GetFileDB" datasource="YourDataSourceHere">

            SELECT * 

            FROM fileDB 

            WHERE fileLocation = <cfqueryparam cfsqltype="cf_sql_varchar" value="#application.documentsDirectory#/#session.UserID#">

                  AND fileName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#documentsDirectory.name#">

                  AND fileOwner = <cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

        </cfquery>

        <!--- If we found nothing about this file in the database already --->

        <cfif GetFileDB.RecordCount IS 0>

        <!--- Here you put your query to create the initial information about this file if it's not already in the database --->

        <!--- Remove everything you don't need from this list -- this is the primary database and you don't necessarily have all this information --->

        <cfquery name="InsertDocumentInformation" datasource="YourDataSourceHere" result="FoundFile">

        INSERT INTO fileDB

                   (fileLocation

                   ,fileName

                   ,fileOwner

                   ,fileDate

                   ,createdDate

                   ,createdBy

                   ,modifiedDate

                   ,modifiedBy

                   ,displayTag

                   )

             VALUES

                   (<cfqueryparam cfsqltype="cf_sql_varchar" value="#application.documentsDirectory#/#session.UserID#">

                   ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#documentsDirectory.name#">

                   ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

                   ,CURRENT_TIMESTAMP

                   ,CURRENT_TIMESTAMP

                   ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

                   ,CURRENT_TIMESTAMP

                   ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

                   ,'Y' <!--- If you want to put a condition in the loop that checks for this tag - you can set this tag to N and the file won't display --->

                   )

        </cfquery>

        <cfquery name="GetFileDB" datasource="YourDataSourceHere">

            SELECT * 

            FROM fileDB 

            WHERE fileKey = <cfqueryparam cfsqltype="cf_sql_varchar" value="#FoundFile.IdentityCol#">

        </cfquery>

        </cfif>

            <!--- Output each file --->

            <cfoutput>

            <form name="editForm" action="">

            <input type="hidden" name="fileKey" value="#GetFileDB.fileKey#">

            <tr valign="bottom">

                <td><input type="text" name="DocumentTitle" value="#GetFileDB.fileTitle#" size="20"></td>

                <td>#fileTypeDisplay#</td>

                <td><a href="#application.documentsDirUrl#/#session.UserID#/#documentsDirectory.name#">#documentsDirectory.name#</a></td>

                <td>#NumberFormat(document_size,"___,___")# #size_type#</td>

                <td>#DateFormat(GetFileDB.createdDate,"short")#</td>

                <td>#GetFileDB.fileOwner#</td>

                <td>#DateFormat(GetFileDB.modifiedDate,"short")#</td>

                <td>#GetFileDB.modifiedBy#</td>

            </tr>

            </cfoutput>

        </cfloop>

        </cfif>

        

	</tbody>

</table>

</font>

<!--- This is the query you would use to insert a file if you know all of this information You will have to do that on different pages

All we know at this point is the UserID Folder and FileName so we aren't inserting all of this information yet - you'll have to build another page for modifying the information about each file

I normally create a table and put buttons in the table for deleting files and modifying their information - then clicking on the name will open the actual file.



<cfquery name="InsertDocumentInformation" datasource="YourDataSourceHere">

INSERT INTO fileDB

           (fileLocation

           ,fileName

           ,fileDescription

           ,fileText

           ,fileTitle

           ,fileCategory

           ,fileDepartment

           ,fileOwner

           ,fileSecurity

           ,fileKeywords

           ,fileDate

           ,createdDate

           ,createdBy

           ,modifiedDate

           ,modifiedBy

           ,displayTag

           )

     VALUES

           (<cfqueryparam cfsqltype="cf_sql_varchar" value="#application.documentsDirectory#/#session.UserID#">

           ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#documentsDirectory.name#">

           ,fileDescription

           ,fileText

           ,fileTitle

           ,fileCategory

           ,fileDepartment

           ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

           ,fileSecurity

           ,fileKeywords

           ,CURRENT_TIMESTAMP

           ,CURRENT_TIMESTAMP

           ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

           ,CURRENT_TIMESTAMP

           ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#session.UserID#">

           ,displayTag

           )

</cfquery>



--->

Open in new window

0
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 33532377
I forgot to close the form - after line 122 add a </form> tag.
0
 

Author Closing Comment

by:JohnMac328
ID: 33533352
Thanks again to both of you.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now