walker6o9
asked on
Force-download
Is there a way to force a download, prompt a save to download, or open in new window when a button is clicked or when a page is loaded?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, that should say line 243, 244, and 245. I cut out some stuff to make the posted code a little shorter.
That code MUST be a separate php program. Say you call it download_annual_report.php
then in your main page you can have <a href='download_annual_repo rt.php'>Do wnload report</a>
then in your main page you can have <a href='download_annual_repo
ASKER
Is there a way I can make that part be called rather than having to click on a link to make it work?
you could use
location('download_annual_ report.php ');
at the end of your existing code.
Note: If you were to remove ALL html code output from the current program, then it could be included at the bottom of that code. and the very first line of your code MUST have <?PHP any white space will cause that header already sent message.
location('download_annual_
at the end of your existing code.
Note: If you were to remove ALL html code output from the current program, then it could be included at the bottom of that code. and the very first line of your code MUST have <?PHP any white space will cause that header already sent message.
ASKER
Why does the html code need to be removed?
ASKER
Also, I tried adding
location('download_annual_ report.php ');
in place of the headers and I got the following error
Fatal error: Call to undefined function location() in C:\wamp\www\annualReport\i ndex.php on line 194
location('download_annual_
in place of the headers and I got the following error
Fatal error: Call to undefined function location() in C:\wamp\www\annualReport\i
oops, me not thinking, it's
header("location: download_annual_report.php ");
but you know what, this still needs the html to be removed.
Headers can not be issued after the start of any html to the browser.
header("location: download_annual_report.php
but you know what, this still needs the html to be removed.
Headers can not be issued after the start of any html to the browser.
ASKER
Is there anyway I can either
a) go to a new url
b) prompt to save
?
It seems like must be a way to do this even if you have html you need on the page
a) go to a new url
b) prompt to save
?
It seems like must be a way to do this even if you have html you need on the page
If you have html on the page, then there must be a reason for the user to see it. this means you'll have to make a <a href> link to click on once they've read the page.
ASKER
I'm trying to do this without making a link. I already did this with a link, but that adds an extra step and it makes for better UX without it.
well to do it without a link, you'll need to not send any html to the browser.
just go through and comment out all html references, if you get error "Headers already sent" then you'll know you missed something. Just make sure the very first line is <?PHP
just go through and comment out all html references, if you get error "Headers already sent" then you'll know you missed something. Just make sure the very first line is <?PHP
ASKER
I have html that has to come before the php though in order to set up the title and some checkboxes.
Ok then the user does have to view the page to see the title and check boxes. this means that you can't automatically just to the download page.
ASKER
I don't want to automatically download the page. I want it to automatically download a pdf when my php function runs.
Is the pdf function a separate program? If it's part of a program that generates html to the browser then you can't issue the header commands to force the download.
ASKER
Okay, so I have an idea for how to fix this that you may be able to help me with.
Here's my issue. I have a bunch of checkboxes that user may or may not click on. When they press a submit button, that information needs to be passed through a php function, which creates a pdf. After the pdf is created, it needs to be automatically loaded.
If there is a way I can pass the information involving whether or not the checkboxes have been clicked on to a separate php file, then I can use the header program to automatically load the pdf. But I don't know how to do that.
Here's my issue. I have a bunch of checkboxes that user may or may not click on. When they press a submit button, that information needs to be passed through a php function, which creates a pdf. After the pdf is created, it needs to be automatically loaded.
If there is a way I can pass the information involving whether or not the checkboxes have been clicked on to a separate php file, then I can use the header program to automatically load the pdf. But I don't know how to do that.
so is your question how to know if a checkbox has been checked?
they are available (if checked) as $_POST['checkbox_name']['v alue']
they are available (if checked) as $_POST['checkbox_name']['v
ASKER
no, i figured out what i was asking is not possible
ASKER
Can you use fopen or any other function in php to open a file in a new window or save it to a disk?
not from php, you could use java script to open a new window.
ASKER
I got it working.
ASKER
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\annualReport\i
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\annualReport\i
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\annualReport\i
Open in new window