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!

Upload a HTML file to a CF coded program

Status
Not open for further replies.

hsienlee

Programmer
Joined
Aug 2, 2001
Messages
3
Location
MY
Hi
I'm now working on a E-learning program using ColdFusion programming language. There are 3 main parties involve on using this program - lecturers, students and the centre administrator.
In the lecturer section, there is one portion which allows the lecturer to upload their html files which have been created by themselves. These html files may contains images in it. The purpose of these html files are the references materials for students to retrieve in the E-learning website.
Here's where my problem occurs. In my source code, I have set a specific path to keep the html files as well as the images in it. For instance,
whenever there is a file n image being uploaded by the lecturer, I'll rename them as:
C:\Inetpub\C:\Inetpub\
While for the HTML file being created by the lecturer himself, when u look at its source code, the path of the image could be something like C:\MyDocuments\chart90.gif

So, once this HTML file is uploaded to the e-learning server, the files will be renamed as topic1.html and the image will be renamed as image1.gif. With this, there's no problem on publshing this HTML file on the E-learning website, but the chart90.gif will not be able to displayed as all since the source code is supposed to link as C:\MyDocuments\chart90.gif while my program has renamed it as C:\Inetpub\
Is there any functions or commands in CF which is able to detect all <img scr..> tag whenever a HTML file is uploading to the server??? And once a <img scr..> tag is detected on teh file uploading, the path of that image linking will be changed over to the path i want it to be immediately.
Is this possible???
Urgent help is needed, thank you. :)
 
hi hsienlee

Well, when you do development on one computer and run the files off of another its a good idea to have the exact same directory structure setup on both machines. Sometimes this is not possible, but the more organized your development directories are (not necessarily your entire computer) is the more organized the web server files will be.

So, use relative paths for image locations. In your HTML refer to charts like <img src=&quot;/images/chart90.gif&quot;>. Keep an images directory in the root of your dev area, as well as in the root of your web server, and move images directly. Every HTML file should be able to find its image.

However, if you're stuck and need to fix this the way you suggest, try this. Set the location of the HTML file on your web server. The first CFFILE reads the file, the script replaces all instances of the first <img> with the second <img>, and the last 2 CFFILEs delete the old and write the new file.


<CFSET outfile = &quot;c:\inetpub\<!--- start delete a file if exists --->


<CFFILE ACTION=&quot;read&quot;
FILE=&quot;#outfile#&quot;
VARIABLE=&quot;outfileContents&quot;>


<CFSCRIPT>
outfileContents = replaceNoCase(outfileContents, '<img src=&quot;c:\wrongpath&quot;>', '<img src=&quot;c:\correctpath&quot;>', 'ALL');
</CFSCRIPT>
<CFFILE ACTION=&quot;DELETE&quot; FILE=&quot;#outfile#&quot;>
<CFFILE ACTION=&quot;write&quot;
FILE=&quot;#outfile#&quot;
OUTPUT=
&quot;#outfileContents#&quot;>
<!--- delete a file if exists --->

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top