简体   繁体   中英

Error uploading a file in Laravel

I'm trying to upload an image in my Laravel application. Everything works fine in localhost . I've tested many times.

So, I've uploaded all files to the server and tested it again. Now when I upload an image, I'm getting the following error:

{"error":{"type":"Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException","message":"","file":"/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php","line":210}}`

Not sure what's wrong in this. Everything is working fine in locahost. I'm using Ubuntu 14.02 in my server. GD library is installed and activated. Composer update has run and all packages are installed.

What might be the problem? Let me know if you need any code snippets. Thanks in advance.

Apparently this was a file permissions issue.

Running php artisan routes (or php artisan route:list for Laravel 5) helped to sort out another problem so the real error message appeared:

{"error":{"type":"ErrorException","message":"copy(/var/www/html/public//u‌​pload/20150413032940.jpeg): failed to open stream: Permission denied","file":"/var/www/html/app/controllers/NominationController.php","l‌​ine":88}}

This means the webserver's user can't write to public/upload . This can be fixed by two methods (the choice depends on preference and setup)

  1. chown user:group /path/to/directory to change the ownership of the directory
  2. chmod 775 /path/to/directory to make the directory writable for all users in the owner's group

Make sure the route which is called when you submit your form is accessible by your form's submission method (eg GET if its method attribute is 'GET')

For instance,

Route::get('/upload', ...)

With

<form action="/upload" method="post">...</form>

in your view would cause the error you get.

I just had this issue and after checking permissions etc it was still occurring... I just tried removing the LEADING slash from the path I had set in my .env file and it worked (even though it was relative to the webserver's public directory so theoretically should have worked with a leading slash denoting to start at webserver root dir)

IMAGE_LIB_PATH="blah/blahblah/"

Anyhow, hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM