milesj / uploader

[Deprecated] A CakePHP plugin for file uploading and validating.
MIT License
193 stars 73 forks source link

Did I set Uploader correctly? #177

Closed rjsandim closed 10 years ago

rjsandim commented 10 years ago

Hi milesj, I having trouble in Uploader configuration, My Configuration follows next:

I've put AttachmentBehavior.php and FileValidationBehavior.php on app/Model/Behavior

I've put uploader.mo and uploader.po on app/Locale/eng/LC_MESSAGES

Composer generated on Vendor all files of composer, mjohnson and autoload.php on app/Vendor

I've put on app/Config/core.php:

require_once dirname(__DIR__) . '/Vendor/autoload.php';

I have a model called Highlight

<?php 
define('UPLOAD_DIR', WWW_ROOT . 'files\uploads\\');

class Highlight extends AppModel {

    public $actsAs = array(
        'Uploader.Attachment' => array(
            'image' => array(
                'tempDir' => TMP,
                'uploadDir' => UPLOAD_DIR,
                'dbColumn' => 'image',
                'finalPath' => 'files\uploads\\'
                )
            )
        );
}

And a Controller:

<?php
App::uses('AppController', 'Controller');

class HighlightsController extends AppController {
    public $uses = array('Highlight');

    public function add() {
        if ($this->Highlight->save($this->request->data, true)) {
            Debugger::dump("It's Worked");
        }
    }
}

And my view on app/View/Highlights/add.ctp

<?php
echo $this->Form->create('Highlight', array('type' => 'file'));
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->end('Submit');

I'm thinking that I'm doing everything all right, but I'm receiving this error: error

I read someone saying that if I use this code my problem would be solved:

<?php
App::uses('AppController', 'Controller');

class HighlightsController extends AppController {
    public $uses = array('Highlight');

    public function add() {
        $this->request->data['Highlight']['image'] = $this->request->data['Highlight']['image']['name']; 
        if ($this->Highlight->save($this->request->data, true)) {
            Debugger::dump("It's Worked");
        }
    }
}

However, the error gone and the file name was saved on database, but the file haven't uploaded and wasn't saved on right folder. Do you have any idea how to help me? I'm using the last Uploader's version, I've tried several configurations to 'uploadDir', I guess that isn't the problem. Thanks for while, do you receive some donate? I've used your code before and I've learned a lot.

milesj commented 10 years ago

Are you copying AttachmentBehavior and FileValidationBehavior into the app? They should reside within the Uploader folder within the Plugin folder. If you install the uploader through composer, it will place everything in the correct locations.

rjsandim commented 10 years ago

Thanks for your quick reaction!

Sorry, It is my first time using composer.

I fix this, and used Composer and the files seems now right. Should I install suggested packages?

If this packages is not necessary for a basic configuration the problem persists, else should I install them?

Should I include 'Uploader' on CakePlugin::load() on Config/bootstrap.php file?

rjsandim commented 10 years ago

Whole configuration was right, the problem was the Model file name, It was 'Highlights' and should be 'Highlight', unfortunately I didn't realize it because the class name was right (Highlight), I've changed Model file name and everything works perfectly. I know, I'm stupid, but It happens in best families. Thanks for your time, and sorry about wasting you time with this.

milesj commented 10 years ago

No problem, glad you figured it out!