@@ -116,7 +116,6 @@ public function fetch(Request $request)
116
116
event (new Catched ($ img ));
117
117
}
118
118
}
119
- $ img ['filename ' ] = $ filename ;
120
119
unset($ img ['file ' ]);
121
120
array_push ($ list , $ img );
122
121
}
@@ -134,42 +133,46 @@ public function fetch(Request $request)
134
133
*
135
134
* @param \Illuminate\Http\Request $request
136
135
*
137
- * @return Array
136
+ * @return Array $info
138
137
*/
139
138
private function download ($ url , $ config )
140
139
{
141
- $ imgUrl = htmlspecialchars ($ url );
142
- $ imgUrl = str_replace ('& ' , '& ' , $ imgUrl );
143
- $ pathRes = parse_url ($ imgUrl );
144
- $ queryString = isset ($ pathRes ['query ' ]) ? $ pathRes ['query ' ] : '' ;
145
- $ imgUrl = str_replace ('? ' . $ queryString , '' , $ imgUrl );
146
- if (strpos ($ imgUrl , 'http ' ) !== 0 ) {
140
+ if (strpos ($ url , 'http ' ) !== 0 ) {
147
141
return $ this ->error ('ERROR_HTTP_LINK ' );
148
142
}
149
-
150
- $ context = stream_context_create (
151
- array ('http ' => array (
152
- 'follow_location ' => false , // don't follow redirects
153
- ))
154
- );
155
- $ file = fopen ($ imgUrl . '? ' . $ queryString , 'r ' , false , $ context );
156
- $ img = stream_get_contents ($ file );
157
- fclose ($ file );
158
- preg_match ('/[\/]([^\/]*)[\.]?[^\.\/]*$/ ' , $ imgUrl , $ m );
159
- $ original = $ m ? $ m [1 ] : '' ;
160
- $ ext = strtolower (strrchr ($ original , '. ' ));
143
+ $ pathRes = parse_url ($ url );
144
+ $ img = new \SplFileInfo ($ pathRes ['path ' ]);
145
+ $ original = $ img ->getFilename ();
146
+ $ ext = $ img ->getExtension ();
161
147
$ title = config ('ueditor.hash_filename ' ) ? md5 ($ original ) . $ ext : $ original ;
162
148
$ filename = $ this ->formatPath ($ config ['path_format ' ], $ title );
163
- return [
149
+ $ info = [
164
150
'state ' => 'SUCCESS ' ,
165
151
'url ' => $ this ->getUrl ($ filename ),
166
152
'title ' => $ title ,
167
153
'original ' => $ original ,
168
154
'source ' => $ url ,
169
- 'size ' => strlen ( $ img ) ,
170
- 'file ' => $ img ,
155
+ 'size ' => 0 ,
156
+ 'file ' => '' ,
171
157
'filename ' => $ filename ,
172
158
];
159
+
160
+ $ context = stream_context_create (
161
+ array ('http ' => array (
162
+ 'follow_location ' => false , // don't follow redirects
163
+ ))
164
+ );
165
+ $ file = fopen ($ url , 'r ' , false , $ context );
166
+ if ($ file === false ) {
167
+ $ info ['state ' ] = 'ERROR ' ;
168
+ return $ info ;
169
+ }
170
+ $ content = stream_get_contents ($ file );
171
+ fclose ($ file );
172
+
173
+ $ info ['file ' ] = $ content ;
174
+ $ info ['siez ' ] = strlen ($ content );
175
+ return $ info ;
173
176
}
174
177
175
178
/**
0 commit comments