1

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.

5
  • Run php artisan routes (or php artisan route:list for Laravel 5) and see if the route you're uploading to exists and is correct. Commented Apr 13, 2015 at 15:19
  • There is an extra / at the trailing part of the URL. Would that make any problem? Commented Apr 13, 2015 at 15:28
  • I changed the / at the end it removed the 301 permanently moved error. Now it shows the following errors: {"error":{"type":"ErrorException","message":"copy(\/var\/www\/html\/public\/\/upload\/20150413032940.jpeg): failed to open stream: Permission denied","file":"\/var\/www\/html\/app\/controllers\/NominationController.php","line":88}} Commented Apr 13, 2015 at 15:31
  • That makes a lot more sense. Seems like you don't have writing permissions with the user that the webserver uses Commented Apr 13, 2015 at 15:32
  • That depends... You can use chown user:group /path/to/directory to change the ownership of the directory. or use chmod 775 /path/to/directory to make it writeable for all users in the owners group. Commented Apr 13, 2015 at 15:39

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Just one more thing to add: Remove any trailing slash / for the Ajax call if it's not defined in the route. I had problem with calling the ajax: example.com/upload/image/ I changed it to example.com/upload/image and it worked. Otherwise you'll get a 301 permanently moved error message.
0

Make sure the route which is called when you submit your form is accessible by your form's submission method (e.g. 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.

4 Comments

I'm uploadig via Ajax. Some other ajax methods are working well. Only the Image uploading is not working
Can you post your route definition, and a basic version of your uploading script ? Are you sure that your route's URL doesn't match another one which only accepts the wrong HTTP method ?
I don't understand, everything is working very well in the localhost. So what might be the problem with the server?
To be honest I have no clue, but maybe posting some code snippets could help me (or someone else) to figure something out... Quite strange, though.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.