Thanks for the great mod!
I can import attachments now, and it shows up correctly... however one problem, when I download, the file is actually a text file, with the following:
<br />
<b>Warning</b>: filesize(): stat failed for /home/public_html/download/37e9d4939a884a82befa6645001c91f63035a48e in <b>/home/public_html/controllers/front/AttachmentController.php</b> on line <b>44</b><br />
<br />
<b>Warning</b>: readfile(/home/public_html/download/37e9d4939a884a82befa6645001c91f63035a48e): failed to open stream: No such file or directory in <b>/home/public_html/controllers/front/AttachmentController.php</b> on line <b>47</b><br />
And I looked at the code (line 44 of the attachment controller):
header('Content-Length: '.filesize(_PS_DOWNLOAD_DIR_.$a->file));
$a->file is the sha1 checksum, I think it should be $a->filename. However I manually added an attachment, and it worked without changing line 44.
I also checked the database and did a var_dump($a), and the $a->file indeed is the checksum. So why it works?
var_dump of working file (manually added attachment):
["file"]=>
string(40) "f80c541a817aaec6db4d9c8460cc5be47054293d"
["file_name"]=>
string(9) "model.pdf"
["file_size"]=>
string(5) "41935"
["name"]=>
string(4) "Test"
["mime"]=>
string(15) "application/pdf"
["description"]=>
string(4) "test"
["position"]=>.....
.....
and this is the var_dump of the bad attachment (imported):
["file"]=>
string(40) "4a4aed26dea405fb231b7c98a75b290bf320e14b"
["file_name"]=>
string(9) "product.pdf"
["file_size"]=>
string(5) "172314"
["name"]=>
string(4) "product.pdf"
["mime"]=>
string(15) "application/pdf"
["description"]=>
string(4) ""
["position"]=>...
...
This is the response header of the manually added attachment (works):
Connection:Keep-Alive
Content-Disposition:attachment; filename="model.pdf"
Content-Encoding:gzip
Content-Transfer-Encoding:binary
Content-Type:application/pdf
Date:Tue, 29 Nov 2016 10:51:25 GMT
Keep-Alive:timeout=1, max=100
Server:Apache
Transfer-Encoding:chunked
Vary:Accept-Encoding,User-Agent
X-Powered-By:PHP/5.6.28
And this is the not working one (imported):
Connection:Keep-Alive
Content-Disposition:attachment; filename="product.pdf"
Content-Encoding:gzip
Content-Length:236
Content-Transfer-Encoding:binary
Content-Type:application/pdf
Date:Tue, 29 Nov 2016 10:51:44 GMT
Keep-Alive:timeout=1, max=100
Server:Apache
Vary:Accept-Encoding,User-Agent
X-Powered-By:PHP/5.6.28
The content length should be 179.18k