CodeSleeve / stapler

ORM-based file upload package for php.
http://codesleeve.com
Other
538 stars 144 forks source link

No error, good data in DB but file is not present on filesystem. #50

Closed prigal closed 10 years ago

prigal commented 10 years ago

Hi,

I use stapler since yesterday, I read the installation manual and everything worked like a charm. Except that today, it's not working, no idea why. I removed almost all the code I added since yesterday but no change.

There is no error, nothing in logs, everything seems to work well but the file is not present in my system folder. Everything is OK in the database, config is default (I tried to generate the config and change defaults folder but without any luck.)

No permission complain, tried with 777, no changes.

I really don't understand what's wrong...

Any idea ?

Edit :

Already tried :

Note : I use andrew13/Laravel-4-Bootstrap-Starter-Site, I'm new to Laravel since yesterday, but not new to frameworks (silex, symfony, ror).

Edit2 : code

City Model

class City extends Eloquent {

    use Codesleeve\Stapler\Stapler;

    public function __construct(array $attributes = array()) {
        $this->hasAttachedFile('cover', [
            'styles' => [
                'large' => '1170x160',
                'medium' => '970x133',
                'small' => '750x103'
            ]
        ]);
        parent::__construct($attributes);
    }

Cities Controller

public function postCreate()
    {

        // Declare the rules for the form validation
        $rules = array(
            'title'   => 'required|min:3',
        );

        // Validate the inputs
        $validator = Validator::make(Input::all(), $rules);

        // Check if the form validates with success
        if ($validator->passes())
        {
            // Update the city data
            $this->city->title            = Input::get('title');
            $this->city->slug             = Str::slug(Input::get('title'));
            $this->city->meta_title       = Input::get('meta-title');
            $this->city->meta_description = Input::get('meta-description');
            $this->city->meta_keywords    = Input::get('meta-keywords');
            $this->city->cover            = Input::file('cover');
            $this->city->opened           = Input::get('opened');
            $this->city->activated        = Input::get('activated');

            // Was the city created?
            if($this->city->save())
            {
                // Redirect to the new city page
                return Redirect::to('admin/cities')->with('success', Lang::get('admin/cities/messages.create.success'));
            }

            // Redirect to the city create page
            return Redirect::to('admin/cities/create')->with('error', Lang::get('admin/cities/messages.create.error'));
        }

        // Form validation failed
        return Redirect::to('admin/cities/create')->withInput()->withErrors($validator);
    }

View

    <form class="form-horizontal" method="post" action="@if (isset($city)){{ URL::to('admin/cities/' . $city->id . '/edit') }}@endif" autocomplete="off" enctype="multipart/form-data">

<!-- City Cover -->
                <div class="form-group {{{ $errors->has('cover') ? 'error' : '' }}}">
                    <div class="col-md-12">
                        <label class="control-label" for="cover">{{{ Lang::get('admin/cities/table.cover') }}}</label>
                        <?= Form::file('cover') ?>
                        {{{ $errors->first('cover', '<span class="help-inline">:message</span>') }}}
                    </div>
                </div>
                <!-- ./ city cover -->

Edit : last one...

New test, adding avatar to my user table... everything work like a charm. City still doesn't work, I don't know why, is there any config stored in some place for each model ?

prigal commented 10 years ago

Ok, solved.

That wasn't a stapler problem, that was a newbie one :)

I was trying to store a whole object in Session, and I don't know why but it was messing with upload in stapler.