@@ -87,6 +87,10 @@ class uploader {
87
87
* @var string */
88
88
protected $ cms = "" ;
89
89
90
+ /** Ouput format.
91
+ * @var string */
92
+ protected $ outputFormat = 'js ' ;
93
+
90
94
/** Magic method which allows read-only access to protected or private class properties
91
95
* @param string $property
92
96
* @return mixed */
@@ -103,7 +107,7 @@ public function __construct() {
103
107
)
104
108
$ this ->cms = $ _GET ['cms ' ];
105
109
106
- // LINKING UPLOADED FILE
110
+ // LINKING UPLOADED FILE
107
111
if (count ($ _FILES ))
108
112
$ this ->file = &$ _FILES [key ($ _FILES )];
109
113
@@ -195,6 +199,11 @@ public function __construct() {
195
199
$ this ->typeURL = "{$ this ->config ['uploadURL ' ]}/ {$ this ->type }" ;
196
200
}
197
201
202
+ // Output Format
203
+ if (isset ($ _GET ['format ' ])) {
204
+ $ this ->outputFormat = $ _GET ['format ' ];
205
+ }
206
+
198
207
// HOST APPLICATIONS INIT
199
208
if (isset ($ _GET ['CKEditorFuncNum ' ])) {
200
209
$ this ->opener ['name ' ] = "ckeditor " ;
@@ -729,11 +738,18 @@ protected function callBack($url, $message="") {
729
738
$ js = $ this ->$ method ($ url , $ message );
730
739
}
731
740
732
- if (!isset ($ js ))
741
+ if ($ this ->outputFormat == 'json ' ) {
742
+ header ('Content-Type: application/json ' );
743
+ $ json = $ this ->callBack_json ($ url , $ message );
744
+ echo json_encode ($ json );
745
+ }
746
+ else {
747
+ if (!isset ($ js )) {
733
748
$ js = $ this ->callBack_default ($ url , $ message );
734
-
735
- header ("Content-Type: text/html; charset= {$ this ->charset }" );
736
- echo "<html><body> $ js</body></html> " ;
749
+ }
750
+ header ("Content-Type: text/html; charset= {$ this ->charset }" );
751
+ echo "<html><body> $ js</body></html> " ;
752
+ }
737
753
}
738
754
739
755
protected function callBack_ckeditor ($ url , $ message ) {
@@ -787,4 +803,25 @@ protected function callBack_default($url, $message) {
787
803
protected function get_htaccess () {
788
804
return file_get_contents ("conf/upload.htaccess " );
789
805
}
806
+
807
+ protected function callBack_json ($ url , $ message ) {
808
+ $ uploaded = !empty ($ url ) ? 1 : 0 ;
809
+ $ result = [
810
+ 'uploaded ' => $ uploaded
811
+ ];
812
+ if ($ uploaded ) {
813
+ $ result ['url ' ] = $ url ;
814
+ $ urlPieces = explode ('/ ' , $ url );
815
+ end ($ urlPieces );
816
+ $ fileNamekey = key ($ urlPieces );
817
+ $ result ['fileName ' ] = $ urlPieces [$ fileNamekey ];
818
+ }
819
+ else {
820
+ $ result ['error ' ] = [
821
+ 'message ' => $ message ,
822
+ ];
823
+ }
824
+ return $ result ;
825
+ }
826
+
790
827
}
0 commit comments