jeger003 Posted September 12, 2010 Share Posted September 12, 2010 hello, i have a code that downloads a file....i want it to forward the user to a newurl.com when they click download here is my code header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($path)) ); header('Content-Disposition: attachment; filename="'.basename($path).'"'); header("Content-Transfer-Encoding: binary\n"); readfile($path); // outputs the content of the file exit(); i want that code to forward to /index.php Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/ Share on other sites More sharing options...
Hypnos Posted September 12, 2010 Share Posted September 12, 2010 You can't with this file. Any additional output will be downloaded as apart of the file you're sending. You need to do it with javascript on the page that they are clicking to download. Like an onclick event. Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1110350 Share on other sites More sharing options...
jeger003 Posted September 12, 2010 Author Share Posted September 12, 2010 do you know where I can find info on it? the download is a simple image button. how can i get javascript on it? thanks Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1110355 Share on other sites More sharing options...
jeger003 Posted September 12, 2010 Author Share Posted September 12, 2010 can someone please help me with this......i know nothing about onclicking Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1110381 Share on other sites More sharing options...
Hypnos Posted September 12, 2010 Share Posted September 12, 2010 You should post in the javascript forum. Here's how I would do it though. Do an onclick event that adds like a 2 second timer to redirect the user to another page. Something like: <a href="download.php" onclick="setTimeout('document.location("http://www.google.com")', 2000); return true">download this!</a> That's not code I've tested (just typed off the top of my head), but should give you the idea. Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1110400 Share on other sites More sharing options...
jeger003 Posted September 13, 2010 Author Share Posted September 13, 2010 im still stuck on this one.......i can get it to work with javascript either....does anyone have any other solution? is there another way to hide download location without using header() function in php? because thats what im using and every time i make it forward to another url i get "Header is already sent" error anyone out there? Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1110591 Share on other sites More sharing options...
jeger003 Posted September 14, 2010 Author Share Posted September 14, 2010 i want to try it another way......im gonna have the download button forward to the location i want and then download file.....but now when i do that i get the error "header already sent" I dont understand why and where I need to look can anyone help me on this one atleast? Link to comment https://forums.phpfreaks.com/topic/213245-how-do-you-forward-to-a-new-url-in-php/#findComment-1111020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.