AV1611 Posted February 8, 2008 Share Posted February 8, 2008 I have a form that when submitted goes to a processor that does this: <?php header('Content-type: application/vnd.ms-word'); header('Content-Disposition: filename=file.doc'); echo "This is a variable: ".$_POST['blah']."\n"; //etc... ?> The form submits and the file is downloaded no problem. How can I make it so the page also forwards to a new page. If I add header('Location: newfile.php'); It forwards but no file is downloaded. Help. Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/ Share on other sites More sharing options...
atlanta Posted February 8, 2008 Share Posted February 8, 2008 If path to file.doc is not in the same folder as this script put the absolute path <?php header('Content-type: application/vnd.ms-word'); header('Content-Disposition: attachment; filename="file.doc"'); readfile('file.doc'); ?> Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461721 Share on other sites More sharing options...
atlanta Posted February 8, 2008 Share Posted February 8, 2008 opps forgot something try that let me know your results <?php header('Content-type: application/vnd.ms-word'); header('Content-Disposition: attachment; filename="file.doc"'); readfile('file.doc'); header('Location: newfile.php'); ?> Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461725 Share on other sites More sharing options...
AV1611 Posted February 8, 2008 Author Share Posted February 8, 2008 I wasn't actually creating a file. Do I have to create the file for the header to work? How does that impact 2 folks using the form at the same time? Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461731 Share on other sites More sharing options...
aschk Posted February 8, 2008 Share Posted February 8, 2008 Providing the readfile function doesn't do an exclusive lock on the file (which it shouldn't because it's doing a read operation) then you will be fine. 2 clients can read the same file at the same time. Files only usually get locked (on linux) when they're being written two or explicitly made to. Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461740 Share on other sites More sharing options...
AV1611 Posted February 8, 2008 Author Share Posted February 8, 2008 Sorry, What I meant was: If I have to take the form, write the variables to the file, then download the file and forward to another page, and two folks do that at the same time, how do I make sure that the file was not changed with the other persons variables? or am I being too careful? Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461788 Share on other sites More sharing options...
aschk Posted February 8, 2008 Share Posted February 8, 2008 Assuming the file you're generating is dynamic (i.e. contains variables written by the user) and is created on the fly by PHP then the best option is to create a temporary file with a random name and delete it once it has been downloaded to the user. Link to comment https://forums.phpfreaks.com/topic/90056-solved-headers-stuff/#findComment-461796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.