File tree Expand file tree Collapse file tree 4 files changed +21
-3
lines changed
Expand file tree Collapse file tree 4 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 213213// Attachments
214214$ client ->api ('attachment ' )->show ($ attachmentId );
215215
216+ $ file_content = $ client ->api ('attachment ' )->download ($ attachmentId );
217+ file_put_contents ('example.png ' , $ file_content );
218+
216219// ----------------------------
217220// News
218221$ client ->api ('news ' )->all ('test ' );
Original file line number Diff line number Diff line change @@ -44,9 +44,9 @@ public function lastCallFailed()
4444 *
4545 * @return array
4646 */
47- protected function get ($ path )
47+ protected function get ($ path, $ decode = true )
4848 {
49- return $ this ->client ->get ($ path );
49+ return $ this ->client ->get ($ path, $ decode );
5050 }
5151
5252 /**
Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ public function show($id)
2222 return $ this ->get ('/attachments/ ' .urlencode ($ id ).'.json ' );
2323 }
2424
25+ /**
26+ * Get attachment content as a binary file
27+ *
28+ * @param string $id the attachment number
29+ * @return string the attachment content
30+ */
31+ public function download ($ id )
32+ {
33+ return $ this ->get ('/attachments/ ' .urlencode ($ id ), false );
34+ }
35+
2536 /**
2637 * Upload a file to redmine
2738 * @link http://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files
Original file line number Diff line number Diff line change @@ -149,12 +149,16 @@ public function getUrl()
149149 * @param string $path
150150 * @return array
151151 */
152- public function get ($ path )
152+ public function get ($ path, $ decode = true )
153153 {
154154 if (false === $ json = $ this ->runRequest ($ path , 'GET ' )) {
155155 return false ;
156156 }
157157
158+ if (!$ decode ) {
159+ return $ json ;
160+ }
161+
158162 return $ this ->decode ($ json );
159163 }
160164
You can’t perform that action at this time.
0 commit comments