Commit 04b4fafb authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

generic image dl #24

parent 934855da
Loading
Loading
Loading
Loading
+1 −12
Original line number Diff line number Diff line
@@ -43,18 +43,7 @@ class ArticleImageDataHandler extends ArticleHandler
                 ->formatFilename($file->getData('path'), $file->getLocalizedData('path'));
             $pathInfo = pathinfo($filename);
             $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName;
             $mimetype = 'application/octet-stream';
             $filesize = $this->fs->fileSize($imagePath);
             $encodedFilename = urlencode($imgName);
             header("Content-Type: $mimetype");
             header("Content-Length: $filesize");
             header('Accept-Ranges: none');
             header('Content-Disposition: attachment' . ";filename=\"$encodedFilename\";filename*=UTF-8''$encodedFilename");
             header('Cache-Control: private'); // Workarounds for IE weirdness
             header('Pragma: public');

             fpassthru($this->fs->readStream($imagePath));
             exit();
             ImageUtils::downloadImage($this->fs, $imagePath, $imgName);
         }
        return NULL;

+1 −12
Original line number Diff line number Diff line
@@ -49,18 +49,7 @@ class BookImageDataHandler extends CatalogBookHandler

        $pathInfo = pathinfo($publicationFile->getData('path'));
        $imagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $pathInfo['filename'] . DIRECTORY_SEPARATOR . $imgName;
        $mimetype = $file->mimetype ?? 'application/octet-stream';
        $filesize = $this->fs->fileSize($imagePath);
        $encodedFilename = urlencode($imgName);
        header("Content-Type: {$mimetype}");
        header("Content-Length: {$filesize}");
        header('Accept-Ranges: none');
        header('Content-Disposition: inline' . ";filename=\"{$encodedFilename}\";filename*=UTF-8''{$encodedFilename}");
        header('Cache-Control: private'); // Workarounds for IE weirdness
        header('Pragma: public');
        fpassthru($this->fs->readStream($imagePath));
        exit;

        ImageUtils::downloadImage($this->fs, $imagePath, $imgName);

    }

+14 −0
Original line number Diff line number Diff line
@@ -30,4 +30,18 @@ class ImageUtils

        return new Filesystem($adapter);
    }

    public static function downloadImage(Filesystem $fs, string $path, string $name){
        $mimetype = 'application/octet-stream';
        $filesize = $fs->fileSize($path);
        $encodedFilename = urlencode($name);
        header("Content-Type: {$mimetype}");
        header("Content-Length: {$filesize}");
        header('Accept-Ranges: none');
        header('Content-Disposition: inline' . ";filename=\"{$encodedFilename}\";filename*=UTF-8''{$encodedFilename}");
        header('Cache-Control: private'); // Workarounds for IE weirdness
        header('Pragma: public');
        fpassthru($fs->readStream($path));
        exit;
    }
}
 No newline at end of file