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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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