karozans Posted July 1, 2008 Share Posted July 1, 2008 Hi everyone, can someone please look at my code and tell me why my download isn't working. I see no errors in IE7 or FF2 or FF3. I have apache running on linux. Basically I have a form. <body dir="LTR" onload="javascript:doWork();" id="main"> <form action="sl_capture_ivt_state_view.htm" enctype="multipart/form-data" method="POST" name="form_out1" target="download"> </form> <iframe title="download" frameborder="no" scrolling="no" marginheight="0" marginwidth="0" name="download"> </iframe> </body> Here is the javascript... function doWork() { document.form_out1.submit(); } then here is the code from sl_capture_ivt_state_view.htm <? $fileName = "/tmp/IVT.tar"; $sumFile = "/home/user/IVTStatus.txt"; $detFile = "/home/user/IVTLog.txt"; $script = "tar -cf $fileName $sumFile $detFile"; system($script); if (file_exists($fileName)) { $size = filesize($fileName); header("Pragma: "); header("Cache-Control: "); header("Content-Type: application/bin"); header("Content-Length: $size"); header('Content-Disposition: attachment; filename="' . basename($fileName) . '"'); header("Content-Location: $fileName"); header("Cache-Control: private"); $handle = fopen($fileName, "rb"); fpassthru($handle); unlink($fileName); } ?> Again like I said, I do not get any browser errors the code simply runs through and stops. I do notice one error in the apache error logs but I am not sure that they have to do with this problem. tar: Removing leading `/' from member names sh: /usr/sbin/sendmail: not found Can anyone help? thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Why do you have an empty form submit to an html file? Anyway, PHP files won't parse in htm files, usually. At least, it won't on my IIS server. If you view source on the blank page does it show the php source? Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 This is apache server running on a linux box. This code is only a small portion of a larger project. I am planning on adding much more hidden fields to post data. I just wanted to get this portion working first. thanks for the reply. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 No no, I don't think you get what he said. PHP doesn't parse HTML files on ANY server unless you explicitly tell it to. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 oh sorry, yes I explicitly have .htm files being parsed by apache/php. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 So, does it stop at a blank page where you can view source? If so, is there anything there when you view source? Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 No it doesn't stop at a blank page, it actually behaves like it should but I get no download prompt and no errors. I should mention this. If I bring up the error log for apache at the same time I bring up the page. Then I hit refresh the page so that the doWork() function runs, if I refresh the error log at the same time as the page is refreshing, once in a while the download prompt will open and work properly. It is like the server is going to fast for the client or something. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 Okay I found something interesting here. If I have this code. <? if ($_SERVER['REQUEST_METHOD'] == "POST") { $fileName = "/tmp/IVT.tar"; $sumFile = "/home/user/IVTStatus.txt"; $detFile = "/home/user/IVTLog.txt"; $script = "tar -cf $fileName $sumFile $detFile"; system($script); if (file_exists($fileName)) { $size = filesize($fileName); header("Pragma: "); header("Cache-Control: "); header("Content-Type: application/bin"); header("Content-Length: $size"); header('Content-Disposition: attachment; filename="' . basename($fileName) . '"'); header("Content-Location: $fileName"); header("Cache-Control: private"); $handle = fopen($fileName, "rb"); fpassthru($handle); unlink($fileName); } } ?> If I navigate directly to the page. myserver/sl_capture_ivt_state_view.htm. Nothing happens as it should because of the... if ($_SERVER['REQUEST_METHOD'] == "POST") but if I remove the if statement and navigate directly to the page the download works beautifully. So if you look at my previous code I am submitting the form as a POST. So I wonder why I am not getting through the if statement. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 No it doesn't stop at a blank page, it actually behaves like it should but I get no download prompt and no errors. If it doesn't prompt but it goes to the page, wouldn't it just be a blank page? I don't understand how it can go to the page like it should and not be blank, since you have no output on that page. try putting echo "test"; right underneath if ($_SERVER['REQUEST_METHOD'] == "POST"){ and see if it does anything. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 Well when I do a post I have the target going to the iframe called "download" If I had the the target as "blank" or "main" then I would get a blank page right? Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 Oh sorry, the echo statement doesn't display anything. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 Try changing sl_capture_ivt_state_view.htm to .php and see if it does the same thing. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 Wow! that works. This is very strange because I have about 200 files that are .htm and they all work with php html and javascript but this one only wants to work with a .php extension. Strange??? Any guesses as to why? Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 Let me make a correction. It works great now on IE7 but not FF3. I am very confussed. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 1, 2008 Author Share Posted July 1, 2008 DOH!!! Okay I swear it worked for 3 times on IE. I then went in and cleared my browser cache and now it doesn't work. I have access to about 14 computers and all of them are experiencing the same behavior. So I don't believe that my browser is having issues. Quote Link to comment Share on other sites More sharing options...
karozans Posted July 2, 2008 Author Share Posted July 2, 2008 Okay guys, I did some more testing and it looks like _blank, _parent, _top works for the target, but when I try to target the iframe that is where it freaks out. I will try to do something else so I don't waste your time. thanks for the help. Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 2, 2008 Share Posted July 2, 2008 So it is still not working after you changed it to a php file? Try giving the iframe an id instead of a name and target it that way: id="iframe1" Quote Link to comment Share on other sites More sharing options...
karozans Posted July 2, 2008 Author Share Posted July 2, 2008 Hi Lemmin, I just got it to work. I did what you said at gave the iframe an id. Here is what else I had going on. I had two iframe, and two hidden forms. In the java code I had... document.form1.submit; document.form2.submit; form1 was going to iframe1 and form2 was going to iframe2 Somehow the php was continueing on before it had a chance to display the dialog box for download. so to fix it I did this. document.form1.action = "iframe1"; document.form1.submit; document.form2.actoin = "iframe2"; document.form2.submit; Again thanks for the help, you set me on the right track to find out what was going on. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.