Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / April 2007



Tip: Looking for answers? Try searching our database.

CFfile - make new directory copy, and force download then go to new URL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jimWPX - 30 Apr 2007 19:15 GMT
Hello ,
I am coding an MP3 download that basically makes a new folder then goes to the
stored location and copies the mp3 and places it in a new folder that later can
be deleted.  Once the folder is made and the mp3 is in it - the idea then is to
force the download by sending it to a force download script in an iframe ( php
script )
Then re-locate the enduser to an alternate page.

Sounds easy?

The problem - Is that the forceddownload works if the mp3 is already there, so
I am guesing that the code runs too fast and when it gets to the force download
script - the mp3 file has not yet been written. yet  If this is so - how can I
make sure that it is there first and then have it wait until the code is run
before it executes the forcedownload and redirect?

Below is the script I am using - the problem is that  each bit of coding works
seperately but when run together it goes straight to the <cflocation> and skips
the download bit.
<cfset newFold =
replace(getCurrentTemplatePath(),getFileFromPath(getCurrentTemplatePath()),'')>

   
    <cfset newPath= #REReplace(#getSong.SongFileLoc1#,"/","\","ALL")#>
    <cfset mp3Path= #REReplace(#getSong.NewFileLoc1#,"/","\","ALL")#>
   
    <cfset newDir="#newFold##newPath#">
    <cfset MusicDir="#newFold##mp3Path##getTuneVerified.TuneKeyCode#">
   

<p><cfoutput><cfset rootPath =
replace(GetDirectoryFromPath("http://"&cgi.server_name&
cgi.path_info),"\","")></cfoutput></p>
   
    <!--- <p><cfoutput>#newDir#</cfoutput></p>  --->
    <cfset downloadMe =
"#rootPath##getSong.NewFileLoc1##getTuneVerified.TuneKeyCode#/#getSong.SongFileN
ame1#">
   
<cfif DirectoryExists(musicDir)>
     <cfquery name="theHits" datasource="theTunes2">
UPDATE Tunecard
SET Downloaded = Downloaded + 1
WHERE Tunecard.TuneID = #getTuneVerified.TuneID#
</cfquery>
    <iframe width=0% height=0% scrolling="no" frameborder="0"
src='<cfoutput>forceDownload.php?file=#getSong.NewFileLoc1##getTuneVerified.Tune
KeyCode#/#getSong.SongFileName1#</cfoutput>'></iframe>

<cflocation addtoken="no" url="#GetArtistInfo.ArtistLandingPage#">
insuractive - 30 Apr 2007 19:33 GMT
You could do something like this instead of writing the file to a temporary
folder:

1) Read contents of MP3 with <cffile variable="sFileContent">
2) <CFHEADER NAME="Content-Disposition" VALUE="attachment;filename="myMP3.mp3">
3) <cfcontent type="unknown><cfoutput>#sFileContent#</cfoutput>

That should serve the file to the user and force the users browser to download
it.
jimWPX - 30 Apr 2007 21:43 GMT
Where do you place the <CFheader> and  how do I make the URL change once the download starts
insuractive - 30 Apr 2007 23:15 GMT
You place the <cfheader> just before the <cfcontent> tag.  If done correctly, the page will result in a download file dialog.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.