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

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

Participant ,
Apr 30, 2007 Apr 30, 2007

Copy link to clipboard

Copied

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.SongFileName1#">

<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.TuneKeyCode#/#getSong.SongFileName1#</cfoutput>'></iframe>


<cflocation addtoken="no" url="#GetArtistInfo.ArtistLandingPage#">
TOPICS
Advanced techniques

Views

548

Translate

Translate

Report

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
Advocate ,
Apr 30, 2007 Apr 30, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Participant ,
Apr 30, 2007 Apr 30, 2007

Copy link to clipboard

Copied

Where do you place the <CFheader> and how do I make the URL change once the download starts

Votes

Translate

Translate

Report

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
Advocate ,
Apr 30, 2007 Apr 30, 2007

Copy link to clipboard

Copied

LATEST
You place the <cfheader> just before the <cfcontent> tag. If done correctly, the page will result in a download file dialog.

Votes

Translate

Translate

Report

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
Documentation