Welcome Guest, Not a member yet? Register   Sign In
forcing file download location dialog rather than viewing linked file?
#1

[eluser]lexusgs430[/eluser]
I have a question I feel I should be able to figure out, but I guess Ive just never done it before and have no idea how it works Smile

So Im trying to make a file downloadable to the user, but I dont want the user to click on the anchor and get a string of garbage, I want them to have the where would you like to save file or at the very least Save file as or open file, dialog pop up.

Im echoing the file location in an anchor($file, 'filename'); helper, which is resulting in the file contents being viewed directly immediately on click. (Which Im assuming is my problem, that I dont know how to fix)
#2

[eluser]bretticus[/eluser]
You need to set the proper headers on the page that renders the file:

Code:
<?php
header('Content-Type: text/plain');
header('Content-Disposition: attachment;filename="youfile.txt"');
header('Cache-Control: max-age=0');
?>

CodeIgniter's Download Helper does this for you also.
#3

[eluser]lexusgs430[/eluser]
ah, ya I saw the download helper and tried it actually but it gave me error message from hell about headers already being set. Hmmm.
#4

[eluser]bretticus[/eluser]
[quote author="lexusgs430" date="1279798480"]ah, ya I saw the download helper and tried it actually but it gave me error message from hell about headers already being set. Hmmm.[/quote]

Remove any whitespace or any other output before calling it. Your error from hell is a pretty common PHP error. You can't output anything before calling header().
#5

[eluser]Seth Setiadha[/eluser]
i'm nu here,

i tried it, seems like it succeeded
but when I open the downloaded file it's only something like 60 byte and there's nothing
i checked the path by viewing the file first and it's fine

sorry if it sounds silly, i put this code on view, it's correct right ?

pls advice
#6

[eluser]Seth Setiadha[/eluser]
nvm, solved it...
i didn't pay attention with -> file_get_contents();




Theme © iAndrew 2016 - Forum software by © MyBB