alph4 Posted October 26, 2007 Share Posted October 26, 2007 Hey everyone! I'm having trouble with reading up an executable and printing it (along with header data of course) to the browser to deliver it. I get a very very small filesize difference using fread(). I checked the original and downloaded files in a binary hex editor and it seems that the same sequence of a word of data is being written to any file I read from and print to the browser. I tested these with text files also and it seems to happen in the ascii form of a few tabs and a new line. I deleted them in the editor and the EXE runs fine. I dont have any echos that would cause this to my knowledge but I can't find out where else they would be coming from. Any ideas? code below. function buildDownload($filepath){ $fsize = filesize($filepath); $fref = fopen($filepath, "r"); $bufsize = 8192; header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="test.txt"'); while(!feof($fref)){ $fdata = fread($fref, $bufsize); print($fdata); } return true; } Quote Link to comment https://forums.phpfreaks.com/topic/74928-executable-delivery/ Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 www.php.net/readfile That will help you, don't use the fopen stuff. That is what readfile was intended for. Quote Link to comment https://forums.phpfreaks.com/topic/74928-executable-delivery/#findComment-378879 Share on other sites More sharing options...
alph4 Posted October 26, 2007 Author Share Posted October 26, 2007 www.php.net/readfile That will help you, don't use the fopen stuff. That is what readfile was intended for. Ok I changed my code to the following but I still get the same bytes written: function buildDownload($filepath){ $fsize = filesize($filepath); header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="test.exe"'); readfile($filepath); return true; } I don't know whats adding the bytes... Quote Link to comment https://forums.phpfreaks.com/topic/74928-executable-delivery/#findComment-378887 Share on other sites More sharing options...
alph4 Posted October 26, 2007 Author Share Posted October 26, 2007 In addition, I have determined that the reason its coming out bad is because it is not transferring with binary. I added the mime header line: header("Content-Transfer-Encoding: binary"); to fix the problem but I still retain the same results. Anyone see anything wrong with this? Quote Link to comment https://forums.phpfreaks.com/topic/74928-executable-delivery/#findComment-378922 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.