/    Sign up×
Community /Pin to ProfileBookmark

Assigning a file to a variable

Hello,

I am attempting to assign a file to a variable and the file that is assigned is based on wether a condition is one option or the other. Would I use fopen() to assign the file on my server to a variable in order to have the user download that file when they click the download now button or is there a better way to accomplish this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@rtretheweyMar 14.2012 — It's not clear what you mean. You can load the contents of a file into a variable or you can set a variable to be the name of a file.

It seems likely that assigning the name of the file to your variable is what you want in order to allow a user to download the file. The code that creates the download button then needs to include the value of the variable so it can be passed to the script that sends the file to the user.
Copy linkTweet thisAlerts:
@mccoauthorMar 14.2012 — I created a unique id and then a URL with the unique id that points to the script that is the thank you page. What I was thinking is that I can have the download button be linked to the URL that links to the thank you page script which will contain validation of the unique id and headers to force the download to be saved to the users computer. The reason I was asking about assigning the file name to the variable was to use it as the readfile header when the download button is clicked.

Does this make sense?

Will it work?
Copy linkTweet thisAlerts:
@mccoauthorMar 15.2012 — Here is the code that I would like to use the fopen with:

[code=php]

if ($r == 9.99) {
$package = fopen('/cover01.zip');
} elseif ($r == 14.99) {
$package = fopen('/cover02.zip');
} else { // Problem finding the order!
trigger_error('The transaction could not be found in the table!');
}

[/code]


Is this correct syntax and the correct way to use it?
×

Success!

Help @mcco spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...