Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HEEEELLLLPPP:Upload doc from a drive to intranet

Status
Not open for further replies.

ashw

MIS
Jun 10, 2002
61
CA
How do I upload online document to a list on intranet. I have made a NewDocument.cfm . This is going on the Administrator section. From where I add a document, entring its name, department, description, a browse button that will attach the doc and a submit button. I have written following code for it. I don't know how to code Upload.cfm . Besides, when I want to add that document, I want to add a checkbox with that so I am able to delete it. For general users, I just want to show the list of documents. How do I do that? another thing I need to show an image besides the doc to. I have written the code for it too in documents.cfm. But I don't know how incorporate all those templates??? Please help
<!---CFincludes header, Css style sheet and Side Menu--->
<cfinclude template=&quot;/Header.cfm&quot;>
ADD NEW DOCUMENT CODE
<SCRIPT LANGUAGE=&quot;JavaScript&quot;><!--
function submitforms(){
Upload.submit()
Attachment.submit()
}
//--></SCRIPT>

<body>
<cfform action=&quot;Upload.cfm&quot; method=&quot;POST&quot; enablecab=&quot;No&quot; name=&quot;Upload&quot; enctype=&quot;multipart/form-data&quot; preservedata=&quot;Yes&quot;>
<table border=&quot;0&quot;>
<tr>
<th colspan=&quot;2&quot;>Add a New Department Document</th>
</tr>
<tr>
<td>Document Name</td>
<td>
<cfinput type=&quot;text&quot; name=&quot;wpTitle&quot;>
</td>
</tr>
<tr>
<td>Department</td>
<td>
<input type=&quot;hidden&quot; name=&quot;wpdept&quot;>
<cfoutput>#Session.Auth.Dept#</cfoutput></td>
</tr>
<tr>
<td></td>
<td>
<input type=&quot;hidden&quot; name=&quot;wptype&quot; value=&quot;7&quot;>
</td>
</tr>
<tr>
<td>Description</td>
<td>
<cfinput type=&quot;text&quot; name=&quot;wpDescription&quot;>
</td>
</tr>
<tr>
<td></td>
<td><input type=&quot;hidden&quot; name=&quot;wpDateCreated&quot; value=&quot;#CreateODBCDateTime(Now())#&quot;</td>
</tr>
<tr>
<td colspan=&quot;2&quot;>
<tr>
<td colspan=&quot;2&quot;></cfform>

<cfform action=&quot;Upload.cfm&quot; method=&quot;POST&quot; enablecab=&quot;No&quot; name=&quot;Attachment&quot; enctype=&quot;multipart/form-data&quot; preservedata=&quot;Yes&quot;>
<input type=&quot;file&quot; name=&quot;wpattachment&quot; size=&quot;40&quot; accept=&quot;application/msword,application/msexcel,application/pdf,text/html,application/rtf&quot; class=&quot;button2&quot;>
<tr>
<td colspan=&quot;2&quot;></td>
</cfform>
<tr>
<td colspan=&quot;2&quot;></tr>
<tr>
<td colspan=&quot;2&quot;>
<input type=&quot;submit&quot; value=&quot;Submit Forms&quot; onClick=&quot;submitforms()&quot;>
</td>
</tr>
</table>


</body>
<!---CFInclude Footer--->
<cfinclude template=&quot;/footer.cfm&quot;>

How do I code Upload, besides I also have to specify that if extension is doc then show MSword.gif
 
&quot;
cffile
Description Handles all interactions with files. The attributes you use with cffile depend on the
value of the action attribute. For example, if the action = &quot;write&quot;, use the
attributes associated with writing a text file.
Note
In the ColdFusion Administrator, the security settings on the Tag Restrictions page
under ColdFusion Basic Security may prevent cffile from executing. For cffile to
execute, it needs to be enabled. For more information, see Advanced ColdFusion
Administration.
If you write ColdFusion applications that run on a server used by multiple
customers, consider the security of the files that could be uploaded or otherwise
manipulated by cffile. For more information, see Advanced ColdFusion
Administration.
cffile actions
The following sections describe how to use the different actions available with the
cffile tag:
• cffile action = &quot;upload&quot; on page 71
• cffile action = &quot;move&quot; on page 75
• cffile action = &quot;rename&quot; on page 76
• cffile action = &quot;copy&quot; on page 77
• cffile action = &quot;delete&quot; on page 78
• cffile action = &quot;read&quot; on page 79
• cffile action = &quot;readBinary&quot; on page 80
• cffile action = &quot;write&quot; on page 81
• cffile action = &quot;append&quot; on page 84
Alphabetical List of ColdFusion Tags 71
cffile action = &quot;upload&quot;
Description Uploads upload a file specified in a form field to a directory on the Web server.
Note
The mode attribute applies only to ColdFusion on Solaris and HP-UX.
Category File management tags
Syntax <cffile action = &quot;upload&quot;
fileField = &quot;formfield&quot;
destination = &quot;full_path_name&quot;
nameConflict = &quot;behavior&quot;
accept = &quot;mime_type/file_type&quot;
mode = &quot;permission&quot;
attributes = &quot;file_attributes&quot;>
See also cfdirectory
Attributes
Attribute Description
fileField Required. The name of the form field that was used to select the file.
Note: Do not use pound signs (#) to specify the field name.
destination Required. The full pathname of the destination directory or full
pathname of the file on the Web server where the file is saved. A
trailing slash must be included in the target directory. Use the
backward slash (\) on Windows; use the forward slash (/) on UNIX.
Note: The directory does not have to be below the root of the Web
server document directory.
nameConflict Optional. Default is Error. Determines how to handle the file if its
name conflicts with the name of a file that already exists in the
directory. Options are:
• Error Default. The file is not saved, ColdFusion stops processing
the page and returns an error.
• Skip Neither saves the file nor throws an error. This setting allows
custom behavior based on file properties.
• Overwrite Replaces an existing file, if it has the same name as
the cffile destination.
• MakeUnique Generate a unique filename for the upload. The
name is stored in the file object variable serverFile. You can
use this variable to record the name used when the file was saved.
accept Optional. Limit the file types accepted. Enter one or more
comma-delimited MIME types that you want to accept. For example,
to allow uploads of GIF and Microsoft Word files, enter:
accept = &quot;image/gif, application/msword&quot;
The browser uses the file extension to determine file type.
72 Chapter 2 ColdFusion Tags
Example The following example creates a unique filename if there is a name conflict when the
file is uploaded on Windows:
<cffile action = &quot;upload&quot;
fileField = &quot;FileContents&quot;
destination = &quot;c:\web\uploads\&quot;
accept = &quot;text/html&quot;
nameConflict = &quot;MakeUnique&quot;>
Note
On Windows, you must include the backward slash (\) after the destination directory
name. On UNIX, you must include the forward slash (/) after the destination
directory. In this example, the specified destination directory is &quot;uploads.&quot;
Usage After a file upload is completed, you can retrieve status information using file upload
parameters. The status information includes data about the file, such as the file’s
name and the directory where it was saved. File upload status parameters use the
cffile prefix; for example, cffile.clientDirectory. The file status parameters can
be used anywhere other ColdFusion parameters can be used.
mode Optional. Defines permissions for an uploaded file on UNIX and Linux
platforms. Ignored in Windows. Option values correspond to the octal
values (not symbolic) of the UNIX chmod command. Permissions are
assigned for owner, group, and other, respectively.
For example:
• mode = &quot;644&quot; Assigns read/write permissions for the owner, and
read permissions for the group and other.
• mode = &quot;666&quot; Assigns read/write permissions for owner, group,
and other.
• mode = &quot;777&quot; Assigns read, write, and execute permissions for
all.
attributes Optional. A comma-delimited list of file attributes to be set on the file
being uploaded. Options are:
• readOnly
• temporary
• archive
• hidden
• system
• normal
If attributes is not used, the file’s attributes are maintained. If
normal is specified with other attributes, normal is overridden by
whatever other attribute is specified.
Individual attributes must be specified explicitly. For example, if you
specify only the readOnly attribute, all other existing attributes are
overwritten.
Attribute Description
Alphabetical List of ColdFusion Tags 73
Note
Although the file prefix is still supported, it has been deprecated in favor of the
cffile prefix.
The following file upload status parameters are available after an upload.
Parameter Description
attemptedServerFile Initial name ColdFusion used when attempting to save a file
clientDirectory Directory location of the file uploaded from the client’s
system
clientFile Name of the file uploaded from the client’s system
clientFileExt Extension of the uploaded file on the client’s system without a
period, for example, txt not .txt
clientFileName Filename, without an extension, of the uploaded file on the
client’s system
contentSubType MIME content subtype of the saved file
contentType MIME content type of the saved file
dateLastAccessed Date and time the uploaded file was last accessed
fileExisted Indicates (Yes or No) whether or not the file already existed
with the same path
fileSize Size of the uploaded file
fileWasAppended Indicates (Yes or No) whether ColdFusion appends the
uploaded file to an existing file
fileWasOverwritten Indicates (Yes or No) whether ColdFusion overwrites a file
fileWasRenamed Indicates (Yes or No) whether the uploaded file is renamed to
avoid a name conflict
fileWasSaved Indicates (Yes or No) whether Cold Fusion saves a file
oldFileSize Size of a file that was overwritten in the file upload operation
serverDirectory Directory of the file saved on the server
serverFile Filename of the file saved on the server
serverFileExt Extension of the uploaded file on the server, without a period
serverFileName Filename, without an extension, of the uploaded file on the
server
timeCreated Time the uploaded file was created
timeLastModified Date and time of the last modification to the uploaded file
74 Chapter 2 ColdFusion Tags
Tip
Use the cffile prefix to refer to these parameters; for example,
#cffile.fileExisted#.
Note
File status parameters are read-only. They are set to the results of the most recent
cffile operation. (If two cffile tags execute, the results of the first are overwritten
by the subsequent cffile operation.)
Example UNIX The following three examples show the use of the mode attribute on UNIX. The first
example creates the file /tmp/foo with permissions defined as: owner = read/
write, group = read, other = read.
<cffile action = &quot;write&quot;
file = &quot;/tmp/foo&quot;
mode = 644>
This example appends to the specified file and makes permissions read/write (rw)
for all.
<cffile action = &quot;append&quot;
destination = &quot;/home/tomj/testing.txt&quot;
mode = 666
output = &quot;Is this a test?&quot;>
This example uploads a file and sets permissions to owner/group/other = read/
write/execute.
cffile action = &quot;upload&quot;
fileField = &quot;fieldname&quot;
destination = &quot;/tmp/program.exe&quot;
mode = 777>

&quot;
 
thats kind of jumbled, but thats the cffile reference from macromedia you will need to use it on your action page. refereing to the FORM.nameoffileform

hope that helps
 
I am very new in coldfusion so all the above is bit intimidating to me. let me read a little about uploading files using the <CFFILE> tag
 
I am very new in coldfusion so all the above is bit intimidating for me. let me read a little about uploading files using the <CFFILE> tag and then I will ask you what to do
 
Okay, I did a little reading and I don't think I should have any problems on using CFFILE tag. One question. Two type of staff are accessing my intranet. user and admin.
the admins can delete, add a document however users can only see it. so the admin page page will contain a delete button and coresponding checkboxes along with the list of uploaded documents. the users will only view the list. how do I do that?
 
How do admins and/or users login (ie - what distinguishes one from the other as far as the server is concerned)?

Whatever that disguishing factor is, whether it's checking IsAuthenticated(), or checking their user id against a database, or checking their IP/remote_host, you would simply need to check that factor in a CFIF...

Code:
<table>
<CFLOOP index=&quot;whichfile&quot; list=&quot;#filelist#&quot;>
<CFOUTPUT><tr><td><a href=&quot;#whichfile#&quot;>#whichfile#</td><td> : : checkboxes, or whatever : : </td><td>
<CFIF IsAuthenticated(&quot;FileAdmin&quot;)>
       :
     display delete button *
       :
</CFIF>
</td></tr></CFOUTPUT>
</CFLOOP>
</table>
       :
     display file
       :

* the delete button, I've found, is usually a self-contained POSTing form with some hidden fields to hold the filename, etc... that way at least you're not passing stuff on the URL.
Code:
<form action=&quot;actionpage.cfm&quot; method=&quot;post&quot;>
  <input type=&quot;hidden&quot; name=&quot;filename&quot; value=&quot;#whichfile#&quot;>
  <input type=&quot;hidden&quot; name=&quot;actionmode&quot; value=&quot;delete&quot;>
  <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Delete this file&quot;>
</form>

then actionpage.cfm would be something like:
Code:
<cfif IsAuthenticated(&quot;FileAdmin&quot;) AND IsDefined(&quot;FORM.filename&quot;) AND IsDefined(&quot;FORM.actionmode&quot;) AND FORM.actionmode EQ delete>
          :
      delete the file
          :
</cfif>

But I dare say... if you're truly &quot;very new&quot; to ColdFusion, you're undertaking a pretty complex project for getting your feet wet... one that has a lot of potential &quot;gotcha&quot;s. If you aren't deligent and you don't know exactly what you're doing, you may open the file system up quite a bit more than you had anticipated.
Hope it helps,
-Carl
 
Can anyone PLEASE look at my code to see what I am doing wrong?
I add documents from an add new document form. the documents are on coldfusion server directory d:/intranet Online directory (all the documents added are displayed in a list with a corresponding checkbox for delete operation) I have written the following code for add new document form

<!---CFincludes header, Css style sheet and Side Menu--->
<cfinclude template=&quot;/Header.cfm&quot;>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;><!--
function submitforms(){
Upload.submit()
Attachment.submit()
}
//--></SCRIPT>

<body>
<cfform action=&quot;Upload.cfm&quot; method=&quot;POST&quot; enablecab=&quot;No&quot; name=&quot;Upload&quot; enctype=&quot;multipart/form-data&quot; preservedata=&quot;Yes&quot;>
<table border=&quot;0&quot;>
<tr>
<th colspan=&quot;2&quot;>Add a New Department Document</th>
</tr>
<tr>
<td>Document Name</td>
<td>
<cfinput type=&quot;text&quot; name=&quot;wpTitle&quot;>
</td>
</tr>
<tr>
<td>Department</td>
<td>
<input type=&quot;hidden&quot; name=&quot;wpdept&quot;>
<cfoutput>#Session.Auth.Dept#</cfoutput></td>
</tr>
<tr>
<td></td>
<td>
<input type=&quot;hidden&quot; name=&quot;wptype&quot; value=&quot;7&quot;>
</td>
</tr>
<tr>
<td>Description</td>
<td>
<cfinput type=&quot;text&quot; name=&quot;wpDescription&quot;>
</td>
</tr>
<tr>
<td></td>
<td><input type=&quot;hidden&quot; name=&quot;wpDateCreated&quot; value=&quot;#CreateODBCDateTime(Now())#&quot;</td>
</tr>
<tr>
<td colspan=&quot;2&quot;>
<tr>
<td colspan=&quot;2&quot;>

<cfform action=&quot;upload.cfm&quot; method=&quot;POST&quot; enablecab=&quot;No&quot; name=&quot;Attachment&quot; enctype=&quot;multipart/form-data&quot; preservedata=&quot;Yes&quot;>
<input type=&quot;file&quot; name=&quot;wpAttachment&quot; size=&quot;40&quot; value=&quot;#wpID#&quot;
accept=&quot;application/msword,application/msexcel,application/pdf,text/html,application/rtf&quot; class=&quot;button2&quot;>
<tr>
<td colspan=&quot;2&quot;></td>
</cfform>
<tr>
<td colspan=&quot;2&quot;></tr>
<tr>
<td colspan=&quot;2&quot;>
<input type=&quot;submit&quot; value=&quot;Submit Forms&quot; onClick=&quot;submitforms()&quot;>
</td>
</tr>
</table>
</cfform>

</body>
<!---CFInclude Footer--->
<cfinclude template=&quot;/footer.cfm&quot;>
************************************************************
FOLLOWING IS THE CODE FOR Upload.cfm. This outputs the list which consist a checkbox, document image, document name and document size for each document
************************************************************
<cfinclude template=&quot;/Header.cfm&quot;>

<html>
<head>
<title>Untitled</title>
</head>

<body>
<CFFILE ACTION=&quot;UPLOAD&quot; FILEFIELD=&quot;wpAttachment&quot;
DESTINATION=&quot;D:\Intranet Online Documents\#FORM.wpdept#&quot;
NAMECONFLICT=&quot;MAKEUNIQUE&quot;
ACCEPT=&quot;application/msword,application/msexcel,application/pdf,text/html,application/rtf&quot;>
<cfform action=&quot;DeleteDoc.cfm&quot; method=&quot;post&quot;>
<input type=&quot;submit&quot; name=&quot;Delete&quot; value=&quot;Delete&quot;>

<table width=&quot;75%&quot; border=&quot;1&quot;>
<tr>
<td colspan=&quot;4&quot;></td>
</tr>

<cfoutput>
<th colspan=&quot;4&quot;><b><font size=&quot;4&quot;>#dept# Documents</font></b></th>
</cfoutput>

<tr>
<td width=&quot;2%&quot;><input type=&quot;checkbox&quot; onClick=&quot;if (this.checked) CheckAll(this.form); else ClearAll(this.form)&quot;></td>
<td >&nbsp;</td>
<td><div align=&quot;center&quot;><font size=&quot;4&quot;><b><font size=&quot;3&quot;>Name</font></b></font></div></td>

<td width=&quot;9%&quot;>
<div align=&quot;center&quot;><font size=&quot;3&quot;><b>Document Size</b></font></div>
</td>
</tr>
<cfoutput query=&quot;Documents&quot;>

<CFIF #name# Contains &quot;.doc&quot;>
<cfset image = &quot;MSword.gif&quot;>
<CFelseIF #name# Contains &quot;.dot&quot;>
<cfset image = &quot;MSword.gif&quot;>
<cfelseif #name# Contains &quot;.xls&quot;>
<cfset image = &quot;MSExcel.gif&quot;>
<cfelseif #name# Contains &quot;.ppt&quot;>
<cfset image = &quot;MSPPT.gif&quot;>
<cfelseif #name# Contains &quot;.pdf&quot;>
<cfset image = &quot;pdf.gif&quot;>
<cfelseif #name# Contains &quot;.rtf&quot;>
<cfset image = &quot;rtf.gif&quot;>
<cfelseif #name# Contains &quot;.mdb&quot;>
<cfset image = &quot;MSAccess.gif&quot;>
<cfelseif #name# Contains &quot;.htm&quot;>
<cfset image = &quot;Html.gif&quot;>
<CFelse>
<cfset image = &quot;file.gif&quot;>
</CFIF>
<tr>
<cfif Name is not &quot;.&quot; and Name is not &quot;..&quot;>
<td width=&quot;2%&quot;><INPUT type=&quot;checkbox&quot; name=&quot;dID&quot; value=&quot;#wpID#&quot;></td>
<td><img src=&quot;/cfimages/#image#&quot;></td>
<td width=&quot;89%&quot;><a href=&quot;file://uwmspintranet/Intranet online documents/#dept#/#name#&quot; target=&quot;_blank&quot;#name#<a/></td>
<td width=&quot;9%&quot;>#size#</td>
</cfif>
</CFOUTPUT>
</tr>
</table>


</cfform>
</body>
</html>
<cfinclude template=&quot;/footer.cfm&quot;>
 
TRY THIS....
It should not need any medification, It will dump the uploaded file to C:
this is the most basic way to upload a file. you can expand it from here, break it into a form page, and a seperate upload page, whatever you want. this is how CFFILE works.....

Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
	<title>Untitled</title>
</head>

<body>
<cfoutput>
	<form action=&quot;#CGI.SCRIPT_NAME#&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>
		Upload File: <input type=&quot;File&quot; name=&quot;DocUpload&quot;><br>
		<input type=&quot;Submit&quot;>
	</form>
</cfoutput>

<cfif isDefined(&quot;FORM.DocUpload&quot;)>

	<CFFILE action=&quot;UPLOAD&quot;
		filefield=&quot;DocUpload&quot;
		destination=&quot;c:\&quot;>
		
</cfif>
</body>
</html>
 
Have you EVER had cffile working in the simplest form? or did you try like your code shows from the start?

Hope that code helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top