I did a similar script for direct saving encrypted, as a download.
I did use binary content-type, added my own extension.
myimage.jpg
was changed to
myimage.jpg.c128 .... (cast-128 encrypted)
I was afraid that my file should not be treated as binary.
Because I did not want any eventual \r\n and \n conversions to happen.
For example, if a FTP program recognize an extension as ASCII, it will be transfered as text.
All other extensions, also all unknown, will be binary sent.
Simple way to test if your file was encrypted alright,
is of course to make some decrypt tests with such files.
I mean, save the file and try to decrypt the contents.
Here is what I used. It works perfectly!
I can upload a normal file, download/save it as encrypted directly.
I can upload an encrypted file, download/save it as decrypted directly.
(the uploaded file is not even saved in my site
- script takes data directly from temp upload directory [tmp_name]
encrypt it and send it back)
I used this both for encrypted data file, and for normal file decrypted download:
<?php
//Output processed data for download
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: binary");
header("Content-length: ".strlen($out));
header('Content-Disposition: attachment; filename="'.$outname.'"');
print($out);
exit();
?>