Jump to content

Executable delivery


alph4

Recommended Posts

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;


}

Link to comment
https://forums.phpfreaks.com/topic/74928-executable-delivery/
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/74928-executable-delivery/#findComment-378887
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/74928-executable-delivery/#findComment-378922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.