display an image outside of the cold fusion web root

Posted on 2005-04-26
Last Modified: 2013-12-24
I have a simple yet time consuming form that has three steps:
Page 1: fill out your info and include an image of yourself
Page 2: preview the information you submitted including the photo uploaded
Page 3: submit your info(the photo has already been saved during Page 2)

The problem here is that the cold fusion/web server cannot access the photo file since it is outside of its tree

The closest that I have gotten is by creating a file inside the same folder as the pages above with the following data:
<cfcontent type="image/jpg" file="#form.filePath#" reset="no">
and naming it viewFileContent.cfm

Inside of Page 2 I have this:
<cfinclude template="viewFileContent.cfm">

This works in that I do get to see the photo file although that is the entire content of the page.  I need Page 2 to supply a summary of the information submitted along with the picture uploaded.  I see that the <content> tag has a reset feature that should set wether or not the content outside the tag is discarded, however, it is mutually exclusive from the file attribute and that attribute I cannot get rid of because it has the location of the photo image.

Any hints?
Question by:bisonfur37
    LVL 8

    Expert Comment

    Why don't you have page one generate a random key that gets passed to page two which will used as the file name of the uploaded picture into a temp directory. Save the file in a temp directory within the CF tree with the name as the key, then on page two pull up the picture using the key as the name, then when the user submits page two, copy the picture to it's final destination and delete the temp one.

    It looks like you are copying the picture to its final destination before the user has verified thier information.
    LVL 8

    Expert Comment

    Actually on second thought, you don't necessarily need to do it randomly, you could just use the actual name of the file itself. In step 2, pull it from the temp dir. by it's actual name and then move it in step 3.
    LVL 8

    Expert Comment

    Here's the details:

    Page 1
    <SCRIPT LANGUAGE="JavaScript">
     function get_name() {
      var test_array = document.form1.filecontents.value.split("\\");
      var x = test_array.length;

    <form action="file_upload.cfm" enctype="multipart/form-data" method="post" name=form1>
     Enter the file: <input name="filecontents" type="file" size=60>
     <input name="file_name" type="hidden"><br><br>
     <button onClick=get_name();>Submit</button>

    Page 2 (file_upload.cfm)
    <cfset pic_name = "#form.file_name#">

    <!-- show picture -->
    <img src="#pic_name#">

    Page 3
    <!-- move picture -->
    <cffile action=move source="#pic_name#" destination="your path">
    LVL 2

    Author Comment

    My simple solution is as follows:

    The entire viewFileContent.cfm file is:
    <cfcontent type="image/jpg" file="#URL.location#" reset="no">

    Then on another page, after the photo has been uploaded do this:
    <img src="viewFileContent.cfm?location=#form.filePath#" width="250px"><br />

    This works.  The location variable is indeed pointing to a directory outside the document root.
    LVL 9

    Accepted Solution

    im using the same cfcontent for my images.

    im using to prevent leeching to my site

    i got it from here

    in your image tags you use it like this
    <img src="" border="0" alt="My Company Logo">

    you can place your images outside of root or anywhere in your server.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Scale it in WD Gold

    With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

    Suggested Solutions

    Title # Comments Views Activity
    IIS Load balancing 5 51
    Mod rewrite 3 45
    Transferring website to another host 7 50
    Question to locate the problem 18 26
    Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
    Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    779 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

    15 Experts available now in Live!

    Get 1:1 Help Now