3 * @file src/Module/Attach.php
7 namespace Friendica\Module;
9 use Friendica\BaseModule;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Logger;
12 use Friendica\Core\System;
14 use Friendica\Model\Attach as MAttach;
17 * @brief Attach Module
19 class Attach extends BaseModule
22 * @brief Return to user an attached file given the id
24 public static function rawContent(array $parameters = [])
28 throw new \Friendica\Network\HTTPException\BadRequestException();
31 // @TODO: Replace with parameter from router
32 $item_id = intval($a->argv[1]);
34 // Check for existence
35 $item = MAttach::exists(['id' => $item_id]);
36 if ($item === false) {
37 throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
40 // Now we'll fetch the item, if we have enough permisson
41 $item = MAttach::getByIdWithPermission($item_id);
42 if ($item === false) {
43 throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Permission denied.'));
46 $data = MAttach::getData($item);
48 Logger::log('NULL data for attachment with id ' . $item['id']);
49 throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item was not found.'));
52 // Use quotes around the filename to prevent a "multiple Content-Disposition"
53 // error in Chrome for filenames with commas in them
54 header('Content-type: ' . $item['filetype']);
55 header('Content-length: ' . $item['filesize']);
56 if (isset($_GET['attachment']) && $_GET['attachment'] === '0') {
57 header('Content-disposition: filename="' . $item['filename'] . '"');
59 header('Content-disposition: attachment; filename="' . $item['filename'] . '"');