From 745b9cc692c93618573d2cd7d5ff25ac8a5fdbc1 Mon Sep 17 00:00:00 2001 From: Chip Wasson Date: Mon, 29 Aug 2016 11:08:12 -0600 Subject: [PATCH 1/2] Add Content-Disposition to make saving images cleaner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a user tries to save a file from the browser, make the filename the url they entered so they don’t have to type it again. --- http2pic.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/http2pic.class.php b/http2pic.class.php index 79a6254..96aca94 100644 --- a/http2pic.class.php +++ b/http2pic.class.php @@ -231,11 +231,13 @@ class http2pic if ($this->params['type'] === 'png') { header('Content-Type: image/png'); + header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'"'); $result = imagecreatefrompng($this->params['file']); imagepng($result, NULL, 9); } else { header('Content-Type: image/jpeg'); + header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'"'); $result = imagecreatefromjpeg($this->params['file']); imagejpeg($result, NULL, 100); } From 6c1aaeae2a944ff8dce48f19d12f4f80347ddd80 Mon Sep 17 00:00:00 2001 From: Chip Wasson Date: Mon, 29 Aug 2016 11:22:36 -0600 Subject: [PATCH 2/2] Chrome Won't Infer File Extension MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a file extension since the Chrome version I tested didn’t infer the file extension. --- http2pic.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http2pic.class.php b/http2pic.class.php index 96aca94..1c51a51 100644 --- a/http2pic.class.php +++ b/http2pic.class.php @@ -231,13 +231,13 @@ class http2pic if ($this->params['type'] === 'png') { header('Content-Type: image/png'); - header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'"'); + header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'.png"'); $result = imagecreatefrompng($this->params['file']); imagepng($result, NULL, 9); } else { header('Content-Type: image/jpeg'); - header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'"'); + header('Content-Disposition: inline; filename="'.$this->trimToAlphaNumeric($this->params['url']).'.jpg"'); $result = imagecreatefromjpeg($this->params['file']); imagejpeg($result, NULL, 100); }