Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Link to a File

Engaged ,
Jan 28, 2010 Jan 28, 2010

I have a page that lists all the files i a directory with a certain naming structure and links to them, but when I click the link for non .txt files I get an error.  When trying to link to *some* PDFs the error I get is "File does not begin with PDF" or it just freezes.  When trying to link to a .sql file (which is just a text file) it says "page cannot be found".  I'm now looking at ways to force a download and found this: http://lab.artlung.com/coldfusion-force-download/ but when I use cfcontent type="text/plain" (for .sql) it prints out page source code.  When I comment out the cfcontent and cfheader lines and just try to redirect using cflocation I get the error saying I'm trying to use a complex type.  Is there any way to force the passed filename to act as a string?  Am I missing something obvious?

Thanks!

TOPICS
Getting started
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2010 Jan 28, 2010

Filenames will act as a string unless you do something to prevent it.  For what you are attempting, you might have problems with files that contain spaces in the name.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 28, 2010 Jan 28, 2010

Thanks Dan.

There are no spaces in the filename, they are in the format #AlphaNumericCode#_Scrap_#integer#_DPL_yyyymmddhhmiss.ext

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jan 28, 2010 Jan 28, 2010

Where is the directory you are listing files from?

How does this directory relate to your web root?

If the directory is somehow related to your web root, i.e. directly under it or connected with some type of alias or virtural directory, then you should just be able to provide a URL path to the desired file in the href property of an <a>nchor tag.

If the directory is not accessabile through the web root, then you would need to deliver the file content.  This is normally done with the <cfcontent...> tag, but there are other options depending on what exactly you are doing.

I little taste of your code would help greatly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 29, 2010 Jan 29, 2010

The directory I am listing files from is the same of the page I am listing them on. 

I have no problem seeing .cfm files in this directory.


<cfdirectory recurse="yes" directory="#getDirectoryFromPath(getCurrentTemplatePath())#" type="file" name="eg_pipp" action="list">

<cfquery name="files" dbtype="query">
    SELECT    name, directory
    FROM        eg_pipp
    WHERE    name like '#file_start#_%'
</cfquery>
<body>
<cfoutput>
    <cfdump var="#eg_pipp#">
</cfoutput>
<cfoutput query="files">
    <a href="download.cfm?path=#directory#&file=#name#">#name#</a><br />
</cfoutput>
<cfoutput query="files">
    <a href="#name#">#name#</a><br />
</cfoutput>


The first link gives me "

Complex object types cannot be converted to simple values." for PDF but the second link works fine.  For text files (.txt works fine, but .sql does not) I get the same error for the first link and "Page cannot be found" for the second.


Here is download.cfm:


<cfif isDefined("file")>
    <cfset myFile = file>
    <!---<cfcontent type="text/plain">
    <cfheader name="Content-Disposition" value="attachment;filename=#myFile#">--->
    <cflocation url="#path#/#myfile#">
</cfif>


If I uncomment lines 3 and 4 I get the source code for the error message output.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2010 Jan 29, 2010

Is the error occurring on the page with the links or the page with the cfcontent tag?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 29, 2010 Jan 29, 2010

The error is occuring on the page with the cfcontent tag, but even when I try to get directly to the .sql file from the page with the links (without going through download.cfm) I get a 'page cannot be found' message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2010 Jan 29, 2010

Troubleshooting step number 1 - look at your data.  In this case, cfdump var="#url#">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2010 Feb 01, 2010

Here is what I get:

struct
FILEE0J52_Scrap_1_EOD_20100129143822.pdf
PATHC:\Inetpub\wwwroot\portal\manu\ford\eg
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2010 Feb 01, 2010
LATEST

Looking at this code, normally, you have the cfheader and cfcontent tags in "not the usual order".

Try playing with those tags, and hard code various file names.  Once you get that working you can move on to processing variables.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2010 Feb 01, 2010

Looks like a forward slash backslash problem.  Also, your path is not valid for a cflocation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 01, 2010 Feb 01, 2010

Well when I take out the path and just use the filename (all the files I'm dealing with are in the same directory) I still get the Complex Object Types Cannot Be Converted to Simple Values.

Dumpnig the URL var for this attempt gives me:

struct
FILEE0J52_Scrap_1_EOD_20100129143822.pdf
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources