File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed
Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -392,11 +392,13 @@ public function expectsType($mime)
392392
393393 public function attach ($ files )
394394 {
395+ $ finfo = finfo_open (FILEINFO_MIME_TYPE );
395396 foreach ($ files as $ key => $ file ) {
397+ $ mimeType = finfo_file ($ finfo , $ file );
396398 if (function_exists ('curl_file_create ' )) {
397- $ this ->payload [$ key ] = curl_file_create ($ file );
399+ $ this ->payload [$ key ] = curl_file_create ($ file, $ mimeType );
398400 } else {
399- $ this ->payload [$ key ] = " @ { $ file}" ;
401+ $ this ->payload [$ key ] = ' @ ' . $ file . ' ;type= ' . $ mimeType ;
400402 }
401403 }
402404 $ this ->sendsType (Mime::UPLOAD );
Original file line number Diff line number Diff line change @@ -322,13 +322,14 @@ function testParsingContentTypeUpload()
322322
323323 function testAttach () {
324324 $ req = Request::init ();
325-
326- $ req ->attach (array ('index ' => '/dir/filename ' ));
325+ $ testsPath = realpath (dirname (__FILE__ ) . DIRECTORY_SEPARATOR . '.. ' );
326+ $ filename = $ testsPath . DIRECTORY_SEPARATOR . 'test_image.jpg ' ;
327+ $ req ->attach (array ('index ' => $ filename ));
327328 $ payload = $ req ->payload ['index ' ];
328329 // PHP 5.5 + will take advantage of CURLFile while previous
329330 // versions just use the string syntax
330331 if (is_string ($ payload )) {
331- $ this ->assertEquals ($ payload , '@/dir/ filename ' );
332+ $ this ->assertEquals ($ payload , '@ ' . $ filename . ' ;type=image/jpeg ' );
332333 } else {
333334 $ this ->assertInstanceOf ('CURLFile ' , $ payload );
334335 }
You can’t perform that action at this time.
0 commit comments