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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Library Page needs help

Status
Not open for further replies.

WebGodiva

Technical User
Jun 21, 2000
263
US
I've just published (ftp'd) a test site to my new NT server.&nbsp;&nbsp;I had a library page set up where people could upload files to a specific directory and then view the library files in the directory.&nbsp;&nbsp;I keep getting the error that the directory does not exists or that Coldfusion does not recognize the directory.&nbsp;&nbsp;My code is attached below.<br><br>Upload_Openfile.cfm<br><br>&lt;!--- security check ---&gt;<br>&lt;CFIF Find( '..', URL.ServerFile )<br> or Find( '/', URL.ServerFile )<br> &gt;<br> Error: You are not allowed to access this file<br> &lt;CFABORT&gt;<br>&lt;/CFIF&gt;<br><br><br><br>&lt;!--- parameters ---&gt;<br>&lt;CFSET LibraryDirectory = &quot;../htdocs/Penndot/Upload&quot;&gt;<br>&lt;CFSET FilePath = &quot;#LibraryDirectory#/#URL.ServerFile#&quot;&gt;<br><br><br>&lt;!--- extract the file extension ---&gt;<br>&lt;CFSET SeparatorPos = Find( '.', Reverse(URL.ServerFile) )&gt;<br>&lt;CFIF SeparatorPos is 0&gt; &lt;!--- separator not found ---&gt;<br> &lt;CFSET FileExt = ''&gt;<br>&lt;CFELSE&gt;<br> &lt;CFSET FileExt = Right( URL.ServerFile, SeparatorPos - 1 )&gt;<br>&lt;/CFIF&gt;<br><br><br>&lt;!--- find the proper MIME type ---&gt;<br>&lt;CFIF FileExt is ''&gt; &lt;CFSET FileType = &quot;unknown&quot;&gt;<br>&lt;CFELSEIF FileExt is 'pdf'&gt; &lt;CFSET FileType = &quot;application/pdf&quot;&gt;<br>&lt;CFELSEIF FileExt is 'aif'&gt; &lt;CFSET FileType = &quot;audio/aiff&quot;&gt;<br>&lt;CFELSEIF FileExt is 'aiff'&gt; &lt;CFSET FileType = &quot;audio/aiff&quot;&gt;<br>&lt;CFELSEIF FileExt is 'art'&gt; &lt;CFSET FileType = &quot;image/x-jg&quot;&gt;<br>&lt;CFELSEIF FileExt is 'cil'&gt; &lt;CFSET FileType = &quot;application/vnd.ms-artgalry&quot;&gt;<br>&lt;CFELSEIF FileExt is 'gif'&gt; &lt;CFSET FileType = &quot;image/gif&quot;&gt;<br>&lt;CFELSEIF FileExt is 'htm'&gt; &lt;CFSET FileType = &quot;text/html&quot;&gt;<br>&lt;CFELSEIF FileExt is 'html'&gt; &lt;CFSET FileType = &quot;text/html&quot;&gt;<br>&lt;CFELSEIF FileExt is 'pdf'&gt; &lt;CFSET FileType = &quot;application/pdf&quot;&gt;<br>&lt;CFELSEIF FileExt is 'doc'&gt; &lt;CFSET FileType = &quot;application/doc&quot;&gt;<br>&lt;CFELSEIF FileExt is 'wpd'&gt; &lt;CFSET FileType = &quot;application/wpd&quot;&gt;<br>&lt;CFELSEIF FileExt is 'wk4'&gt; &lt;CFSET FileType = &quot;application/wk4&quot;&gt;<br>&lt;CFELSEIF FileExt is 'xls'&gt; &lt;CFSET FileType = &quot;application/xls&quot;&gt;<br><br>&lt;CFELSE&gt; &lt;CFSET FileType = &quot;unknown&quot;&gt;<br>&lt;/CFIF&gt;<br><br><br>&lt;!--- return requested file ---&gt;<br>&lt;CFCONTENT TYPE=&quot;#FileType#&quot; <br> FILE=&quot;#FilePath#&quot;<br>&gt;<br><br>Upload_filelibrary.cfm<br><br>&lt;CFSET LibraryDirectory = &quot;../htdocs/Penndot/Upload&quot;&gt;<br><br>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 FINAL//EN&quot;&gt;<br>&lt;HTML&gt;<br>&lt;HEAD&gt;<br>&lt;META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=ISO-8859-1&quot;&gt;<br>&lt;META NAME=&quot;Generator&quot; CONTENT=&quot;NetObjects Fusion 4.0 for Windows&quot;&gt;<br>&lt;TITLE&gt;Libary of Files on Server&lt;/TITLE&gt;<br><br>&lt;/HEAD&gt;<br>&lt;BODY BGCOLOR=&quot;#FFFFFF&quot; LINK=&quot;#0000FF&quot; VLINK=&quot;#800080&quot; TEXT=&quot;#000000&quot; TOPMARGIN=2 LEFTMARGIN=2 MARGINWIDTH=2 MARGINHEIGHT=2&gt;<br>&lt;CFDIRECTORY<br> action=&quot;LIST&quot;<br> directory=&quot;#LibraryDirectory#&quot;<br> name=&quot;GetFiles&quot;<br>&gt;<br>Misc. html coding to make it look pretty.<br><br>rest of cfml code for this page<br><br>&lt;CFSET Row = 1&gt;<br>&lt;CFOUTPUT query=&quot;GetFiles&quot;&gt;<br>&lt;CFIF Type is &quot;FILE&quot;&gt;<br>&lt;TR bgcolor=&quot;#IIf(Row Mod 2, DE('ffffff'), DE('ffffcf'))#&quot;&gt;<br> &lt;TD width=300&gt;<br> Open File&nbsp;&lt;A href=&quot;Upload_OpenFile.cfm/#Replace(Name,' ','','ALL')#?ServerFile=#URLEncodedFormat(Name)#&quot;&gt;#Name#&lt;/A&gt;<br> &lt;/TD&gt;<br> &lt;TD&gt;#Size#&lt;/TD&gt;<br> &lt;TD nowrap&gt;#DateLastModified#&lt;/TD&gt;<br><br> &lt;CFSET Row = Row + 1&gt;<br><br>&lt;/TR&gt;<br>&lt;/CFIF&gt;<br>&lt;/CFOUTPUT&gt;<br><br>&lt;CFOUTPUT&gt;<br><br>&lt;/TR&gt;<br>&lt;/CFOUTPUT&gt;<br><br>Upload_fileactionform.cfm<br><br>&lt;!--- parameters ---&gt;<br>&lt;CFSET LibraryDirectory = &quot;../htdocs/Penndot/Upload&quot;&gt;<br>&lt;CFSET IsOverwriteEnabled = &quot;YES&quot;&gt;<br><br><br><br>&lt;!--- upload file with unique name ---&gt;<br>&lt;CFFILE<br> action=&quot;UPLOAD&quot;<br> fileField=&quot;UploadedFile&quot;<br> destination=&quot;#LibraryDirectory#/&quot;<br> nameConflict=&quot;MAKEUNIQUE&quot;<br>&gt;<br><br><br>&lt;!--- new name of the uploaded file ---&gt;<br>&lt;CFIF Form.ServerFile is ''&gt;<br> &lt;CFSET NewServerFile = File.ClientFile&gt;<br>&lt;CFELSE&gt;<br> &lt;CFSET NewServerFile = Form.ServerFile&gt;<br>&lt;/CFIF&gt;<br><br><br>&lt;!--- check whether the new file name already exists in the directory ---&gt;<br>&lt;CFDIRECTORY<br> name=&quot;CheckFile&quot;<br> action=&quot;LIST&quot;<br> directory=&quot;#LibraryDirectory#/&quot;<br> filter=&quot;#NewServerFile#&quot;<br>&gt;<br>&lt;CFIF CheckFile.RecordCount is 0<br> or File.ClientFile is File.ServerFile&gt;<br> &lt;CFSET FileAlreadyExists = &quot;NO&quot;&gt;<br>&lt;CFELSE&gt;<br> &lt;CFSET FileAlreadyExists = &quot;YES&quot;&gt;<br>&lt;/CFIF&gt;<br><br>&lt;cfif not isdefined(&quot;session.authenticated&quot;)&gt;<br>&nbsp;&nbsp;&lt;cfoutput&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;You are not authenticated, or your session has timed out<br>&nbsp;&nbsp;&lt;/cfoutput&gt;<br>&nbsp;&nbsp;&lt;cfabort&gt;<br>&lt;/cfif&gt;<br><br>pretty html stuff remainder of code follows:<br><br>&lt;!--- if file name already exists and overwrite is allowed delete file and throw an error ---&gt;<br>&lt;CFIF FileAlreadyExists and not IsOverwriteEnabled&gt;<br><br> &lt;!--- delete file ---&gt;<br> &lt;CFSET TempFilePath = &quot;#LibraryDirectory#/#File.ServerFile#&quot;&gt;<br> &lt;CFFILE<br> action=&quot;DELETE&quot;<br> file=&quot;#TempFilePath#&quot;<br> &gt;<br><br> &lt;FONT size=&quot;+2&quot; color=&quot;ff0000&quot;&gt;&lt;B&gt;File Already Exists&lt;/B&gt;&lt;/FONT&gt;<br> &lt;P&gt;<br> Press Back button and use different file name.<br><br>&lt;!--- ... else rename the file ---&gt;<br>&lt;CFELSE&gt;<br><br> &lt;!--- rename file ---&gt;<br> &lt;CFSET SourceName = LibraryDirectory & '/' & File.ServerFile&gt;<br> &lt;CFSET DestinationName = LibraryDirectory & '/' & NewServerFile&gt;<br> &lt;CFFILE<br> action=&quot;RENAME&quot;<br> source=&quot;#SourceName#&quot;<br> destination=&quot;#DestinationName#&quot;<br> &gt; <br> &lt;P&gt;<br> File was successfully received.<br> &lt;P&gt;<br> Click here to view a listing of the files in the&nbsp;&nbsp;&lt;cfoutput&gt;[&lt;A href=&quot;Upload_FileLibrary.cfm?cfid=#cfid#&cftoken=#cftoken#&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; color: white;&quot;&gt;Library&lt;/A&gt;]&lt;/cfoutput&gt;<br>&lt;/CFIF&gt; <br><br>That's it, I can't figure out what's wrong since everything seems to be pointing to the right direction.&nbsp;&nbsp;Any help would be appreciated.<br>
 
The directory name needs to be a fully qualified path on the drive (example: c:\uploads).&nbsp;&nbsp;It will not work with relative directories... (../uploads).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top