Support the ongoing development of Laravel.io →
Configuration Input Database

newbie alert! i’ve recently moved my Laravel site to Fortrabbit but when i post new images to the site, they do not write to the database or the upload\images directory.

all was functioning properly on the local site and other changes such as posting text, adding users, changing passwords etc, successfully add data to the database

some of the things i’ve tried; changed permissions to group write on the upload directory on the Fortrabbit server with SSH, checked public path with {{ dd(public_path()) }}on local and remote sites, declared public path in \bootstrap\start.php, declared host in \croppa\config.php,

my image model

<?php

class Image extends Eloquent {

	protected $table = 'images';

	public static $uploadRules = array(
		'name' => 'required',
		'attachment' => 'required|mimes:jpg,jpeg,bmp,png|between:0,200'
		);
	
	public function article()
	{
		return $this->belongsTo('Article', 'article_id');
	}

	public function size()
	{
		$size = filesize(public_path() . '/upload/images/' . $this->path);
		return $size;
	}
}

my controller

public function postImage($id)
	{

		if(!Input::hasFile('attachment'))
		{
			return Redirect::to('article/' . $id . '/update')->with('message', 'please attach an image!')->withInput();
		}
		else
		{
			$image = new Image();
			$image->article_id = $id;
			$image->name = Input::get('name');
			$image->path = sha1(uniqid(mt_rand(), TRUE)) . "." . (Input::file('attachment')->getClientOriginalExtension());
			$image->user_id = Auth::id();

			
			$validator = Validator::make(Input::all(), Image::$uploadRules);

			if($validator->fails())
			{
				return Redirect::to('article/' . $id . '/update')->with('message', 'some errors occurred, see below....')->withErrors($validator)->withInput();
			}
			else
			{
				if (Input::file('attachment')->isValid())
					{

					Input::file('attachment')->move(public_path() . '/upload/images', $image->path);
					$image->save();

					return Redirect::to('article/' . $id . '/update')->with('message', 'upload successfull');

				}
				else
				{
					return Redirect::to('article/' . $id . '/update')->with('message', 'invalid file format')->withInput();
				}
			}
		}
		return Redirect::to('article');
	}

my routes

Route::get('article/upload/{num}','ArticleController@postImage');
Route::post('article/upload/{num}', array('before' => 'csrf', 'uses' => 'ArticleController@postImage'));

This is a link

does anyone have any ideas…

thx in advance

Last updated 3 years ago.
0

Are you getting any errors?

Have you checked permissions of the dir?

Last updated 3 years ago.
0

I would also suggest enabling debug if you already haven't done so and seeing if it throws anything. Alternatively, check the laravel logs inside /app/storage/logs and hunt if there are exceptions being thrown.

Also have you tried stepping into the post method (if possible using a debugger) - or at the very least using basic echo statements just to check upto where you reach before things go wrong? To isolate the statement from where the error is being generated?

Last updated 3 years ago.
0

thx for your replies, i actually think it is a permission problem (but i'm not sure how to fix this as i've "chmod -R 777 upload" directory already, should i also chmod /public?

debug is on, but it is not returning anything in the browser, also the error messages in my controller are not being returned. the error i am getting is this one (from the log), to do with line 146 in RouteCollection.php, i'm not sure how to decipher this error.

[2014-11-22 23:18:45] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:146
Stack trace:
#0 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1021): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(989): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(968): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(738): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(708): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Http/FrameGuard.php(38): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#7 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#8 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#9 /var/www/web/wilcannia/htdocs/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#10 /var/www/web/wilcannia/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(606): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#11 /var/www/web/wilcannia/htdocs/public/index.php(49): Illuminate\Foundation\Application->run()
#12 {main} [] []

i'll try to do some die dumps on the controller - see how that goes

zod

Last updated 3 years ago.
0

just thought i'd update this post with what caused me nearly a week of tearing my hair out - i don't have any left now!

the whole problem was caused because in the process of validation, an error was thrown because i had two form close statements within a blade - i also had two forms within that blade.

being a newbie and thinking one might be enough i took out the first ...

{{ Form::close(); }}

it was all fixed by putting that statement back, and changing public path in \bootstrap\start.php & host in \croppa\config.php back to default. all working now...

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.