0

i need to write a php web service to output file to a Windows client application. I have two choice Byte Array and Streaming. Which one is better and easy to implement in PHP?

Thanks for your assistance.

2
  • 1
    what do you mean by Byte Array and Streaming? Commented May 31, 2011 at 4:00
  • I can send out a file to the client as ByteArray or stream it out Commented May 31, 2011 at 9:39

1 Answer 1

0

How about just....

$file = 'some_file.exe';

$_size = filesize($_file);
header('Content-Type: binary/octet-stream');
header('Content-Length: '.$_size);
header('Content-Disposition: attachment; filename="' . basename($file) . '"; size=" . $_size);

@readfile($file);

Note: see the comment about some issues with binary files, however.

Sign up to request clarification or add additional context in comments.

2 Comments

You should use readfile instead of echoing the read contents. I don't think this is really what the OP is asking for though.
@deceze: It's funny (and probably due to fatigue) I was thinking file() first (knew that wasn't right) then went to file_get_contents(). readfile() is, you're right, the better fit. However, I was more just showing that you'd do a combo between headers and outputting content to get the desired result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.