2017-01-16 15 views
0

私は画像をアップロードするコードを書いています。コードは常にファイルのアップロードに失敗しています。Laravel 5.xファイルアップロードが動作しません

class FileTest extends TestCase { 

private $file; 

    public function setUp() 
    { 
     parent::setUp(); 

     $this->file = new Symfony\Component\HttpFoundation\File\UploadedFile(
      'D:/work/gw.png', 
      'gw.png', 
      'image/png', 
      filesize('D:/work/gw.png'), 
      null, 
      true // for $test 
     ); 
    } 

    /** @test */ 
    public function it_uploads_a_valid_file() 
    { 

       $content = $this->post('users/login', ['password' => 'mypass', 
        'email' => '[email protected]'])->response->getContent(); 

     $data = json_decode($content); 
     $token = $data->token; 


     $this->call('POST', 'files/uploadcardimage', [], [], ['image' => $this->file], 
      ['accept' => 'application/png' , 'HTTP_Authorization' => $token]); 

     $this->assertResponseOk(); 
    } 
} 

コントローラー・コード

public function uploadfile(Request $request){ 
     $file = $request->file('image'); 

     if($file->isValid()) 
     { 
      echo "Yes it is valid"; 

     } 
     else 
     { 
      echo "not valid"; 
     } 

     $dir = 'D:/storage/userfiles/78/'; 
     //Move Uploaded File 
     $destinationPath = $dir; 
     $file->move($destinationPath); 
     return response()->json(['success' => '1']); 
    } 

は、スタックトレース

Route::post('files/uploadcardimage', ['middleware'=>'jwt.auth', 'uses' => '[email protected]'])->name('files.upload'); 

routes.phpの次のように私のユニットテストがある

ここで私が間違って何をやっている

を教えてください
[2017-01-16 15:28:15] testing.ERROR: exception 'Symfony\Component\HttpFoundation\File\Exception\FileException' with message 'The file "gw.png" was not uploaded due to an unknown error.' in C:\Users\John\Dropbox\hurry2.0\trunk\vendor\symfony\http-foundation\File\UploadedFile.php:235 
Stack trace: 
#0 C:\Users\John\Dropbox\hurry2.0\trunk\app\Http\Controllers\FilesController.php(117): Symfony\Component\HttpFoundation\File\UploadedFile->move('D:/storage/user...') 
#1 [internal function]: App\Http\Controllers\FilesController->uploadfile(Object(Illuminate\Http\Request)) 
#2 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(80): call_user_func_array(Array, Array) 
#3 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(146): Illuminate\Routing\Controller->callAction('uploadfile', Array) 
#4 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(94): Illuminate\Routing\ControllerDispatcher->call(Object(App\Http\Controllers\FilesController), Object(Illuminate\Routing\Route), 'uploadfile') 
#5 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#6 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#7 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#8 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#9 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(96): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#10 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(54): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(App\Http\Controllers\FilesController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'uploadfile') 
#11 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Route.php(174): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'App\\Http\\Contro...', 'uploadfile') 
#12 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Route.php(140): Illuminate\Routing\Route->runController(Object(Illuminate\Http\Request)) 
#13 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Router.php(724): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request)) 
#14 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#15 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#16 C:\Users\John\Dropbox\hurry2.0\trunk\app\Http\Middleware\JWTAuthenticate.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#17 [internal function]: App\Http\Middleware\JWTAuthenticate->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#18 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#19 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#20 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#21 C:\Users\John\Dropbox\hurry2.0\trunk\app\Http\Middleware\VerifyCsrfToken.php(18): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#22 [internal function]: App\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#23 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#24 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#25 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#26 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#27 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#28 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#29 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#30 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#31 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#32 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#33 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#34 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#35 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#36 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#37 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#38 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#39 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#40 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#41 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#42 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#43 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#44 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#45 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#46 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#47 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#48 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Router.php(726): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#49 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Router.php(699): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request)) 
#50 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Router.php(675): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) 
#51 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(246): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) 
#52 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) 
#53 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#54 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#55 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) 
#56 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(136): call_user_func_array(Array, Array) 
#57 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
#58 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#59 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
#60 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
#61 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
#62 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) 
#63 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php(515): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) 
#64 C:\Users\John\Dropbox\hurry2.0\trunk\tests\FileTest.php(37): Illuminate\Foundation\Testing\TestCase->call('POST', 'files/uploadcar...', Array, Array, Array, Array) 
#65 [internal function]: FileTest->it_uploads_a_valid_file() 
#66 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestCase.php(909): ReflectionMethod->invokeArgs(Object(FileTest), Array) 
#67 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestCase.php(768): PHPUnit_Framework_TestCase->runTest() 
#68 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestResult.php(612): PHPUnit_Framework_TestCase->runBare() 
#69 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestCase.php(724): PHPUnit_Framework_TestResult->run(Object(FileTest)) 
#70 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult)) 
#71 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\Framework\TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult)) 
#72 C:\Users\John\Dropbox\hurry2.0\trunk\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult)) 
#73 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array) 
#74 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true) 
#75 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main() 
#76 {main} 
[2017-01-16 15:28:15] testing.ERROR: #######Unknown error. This exception is not handled by the Handler. Attaching the message ########## 0=The file "gw.png" was not uploaded due to an unknown error. ["#0 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\app\\Http\\Controllers\\FilesController.php(117): Symfony\\Component\\HttpFoundation\\File\\UploadedFile->move('D:/storage/user...')\n#1 [internal function]: App\\Http\\Controllers\\FilesController->uploadfile(Object(Illuminate\\Http\\Request))\n#2 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php(80): call_user_func_array(Array, Array)\n#3 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(146): Illuminate\\Routing\\Controller->callAction('uploadfile', Array)\n#4 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(94): Illuminate\\Routing\\ControllerDispatcher->call(Object(App\\Http\\Controllers\\FilesController), Object(Illuminate\\Routing\\Route), 'uploadfile')\n#5 [internal function]: Illuminate\\Routing\\ControllerDispatcher->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#6 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#7 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#8 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#9 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(96): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\n#10 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php(54): Illuminate\\Routing\\ControllerDispatcher->callWithinStack(Object(App\\Http\\Controllers\\FilesController), Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request), 'uploadfile')\n#11 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(174): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request), 'App\\\\Http\\\\Contro...', 'uploadfile')\n#12 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php(140): Illuminate\\Routing\\Route->runController(Object(Illuminate\\Http\\Request))\n#13 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(724): Illuminate\\Routing\\Route->run(Object(Illuminate\\Http\\Request))\n#14 [internal function]: Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#15 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#16 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\app\\Http\\Middleware\\JWTAuthenticate.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#17 [internal function]: App\\Http\\Middleware\\JWTAuthenticate->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#18 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#19 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#20 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#21 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\app\\Http\\Middleware\\VerifyCsrfToken.php(18): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#22 [internal function]: App\\Http\\Middleware\\VerifyCsrfToken->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#23 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#24 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#25 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#26 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\View\\Middleware\\ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#27 [internal function]: Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#28 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#29 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#30 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#31 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Session\\Middleware\\StartSession.php(64): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#32 [internal function]: Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#33 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#34 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#35 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#36 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#37 [internal function]: Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#38 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#39 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#40 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#41 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Cookie\\Middleware\\EncryptCookies.php(59): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#42 [internal function]: Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#43 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#44 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#45 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#46 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#47 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#48 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(726): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\n#49 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(699): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))\n#50 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php(675): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))\n#51 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(246): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))\n#52 [internal function]: Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))\n#53 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#54 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php(44): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#55 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))\n#56 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(136): call_user_func_array(Array, Array)\n#57 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))\n#58 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#59 [internal function]: Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))\n#60 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))\n#61 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(132): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))\n#62 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php(99): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))\n#63 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\MakesHttpRequests.php(515): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))\n#64 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\tests\\FileTest.php(37): Illuminate\\Foundation\\Testing\\TestCase->call('POST', 'files/uploadcar...', Array, Array, Array, Array)\n#65 [internal function]: FileTest->it_uploads_a_valid_file()\n#66 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php(909): ReflectionMethod->invokeArgs(Object(FileTest), Array)\n#67 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php(768): PHPUnit_Framework_TestCase->runTest()\n#68 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestResult.php(612): PHPUnit_Framework_TestCase->runBare()\n#69 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestCase.php(724): PHPUnit_Framework_TestResult->run(Object(FileTest))\n#70 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))\n#71 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\Framework\\TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\n#72 C:\\Users\\John\\Dropbox\\hurry2.0\\trunk\\vendor\\phpunit\\phpunit\\src\\TextUI\\TestRunner.php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))\n#73 C:\\xampp\\php\\pear\\PHPUnit\\TextUI\\Command.php(176): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)\n#74 C:\\xampp\\php\\pear\\PHPUnit\\TextUI\\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)\n#75 C:\\xampp\\php\\phpunit(46): PHPUnit_TextUI_Command::main()\n#76 {main}"] 

答えて

1

私はよく分からないが、あなたが保存するためのアップロードパスとファイル名の両方を指定する必要があり、このIlluminate\Http\UploadedFile

/** 
    * @param $file 
    * @return \Illuminate\Http\UploadedFile|string 
    */ 
    private function getFileInstance($file = null) 
    { 
     if (!empty($file)) { 
      $path = base_path($file); 
      $file = new UploadedFile($path, basename($path), mime_content_type($path), filesize($path), null, true); 
     } 
     return $file; 
    } 
0

はこれにあなたのコントローラのコード​​を変更してみてください:

$file->move($destinationPath, $file->getClientOriginalName()); 
0

を試してみてくださいファイル。

$ext = $file->getClientOriginalExtension(); // getting image extension 
$fileName = uniqid().'.'.$ext; // renameing image 
$file->move($destinationPath, $file->getClientOriginalName()); // uploading the file 
0

あなたのコントローラでファイル名が欠落しているが$file->move($destinationPath, $file->getClientOriginalName());

に​​を変更してみてください
関連する問題