Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:24:24+00:00 2026-06-05T13:24:24+00:00

I am learning CakePHP 2.0, and created a sample test application, where user can

  • 0

I am learning CakePHP 2.0, and created a sample test application, where user can submit a file at the time of registration.

below is the database table

users Table

id Auto_Increment
first_name
last_name
email
doc_file

And also created User.php and UsersController.php

and below are the content code in UsersController.php

UsersController.php

class UsersController extends AppController{

    public $helpers = array('Html', 'Form');


    public function index(){
        $this->set('user1', $this->User->find('all'));
    }


    public function register(){
        if ($this->request->is('post')){
            if ($this->User->save($this->request->data)){
                //move_uploaded_file($this->data['Model']['field']['tmp_name'], WWW_ROOT.DS.'xxx');

                move_uploaded_file($this->data['User']['doc_file']['tmp_name'], WWW_ROOT.DS.'hello.doc');

                $this->Session->setFlash('User is created');
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash('Cannot register a user');
            }
        }
    }
}

And in Views, I have created a two files ie index.ctp and register.ctp with a directory Users in View directory

code content of register.ctp

register.ctp

<?php

    echo $this->Form->create('User', array('type'=>'file'));
    echo $this->Form->input('first_name', array('label'=>'First Name'));
    echo $this->Form->input('last_name', array('label'=>'Last Name'));
    echo $this->Form->input('email');
    echo $this->Form->input('doc_file', array('type'=>'file'));
    echo $this->Form->end('Register');
?>  

And when run this page, and fill up all information, it gives an error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

And below is the query I got, where it is inserting an array into doc_file

SQL Query: INSERT INTO `database_db`.`users` (`first_name`, `last_name`, `email`, `doc_file`) VALUES ('master', 'shifu', 'shifu@k.com', Array)

What i am trying :

While user is registering, the file name should be random and it should be move to

localhost/mysite/app/webroot/files/user_data/ or
localhost/mysite/app/webroot/files/user_data/user_id_directory/

its good, if it creates the userid directory and storing the file in its parent user directory

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:24:24+00:00Added an answer on June 5, 2026 at 1:24 pm

    The problem is that CakePHP is seeing the doc_file field and trying to insert it into the database.

    After Cake has processed the form submission, doc_file contains an array of values.

    You can fix it by doing the following:

    In your view:

    echo $this->Form->input('new_doc_file', array('type'=>'file'));
    

    In your controller:

    if ($this->request->is('post')){
        $this->data['User']['doc_file'] = WWW_ROOT.DS.'hello.doc';
        if ($this->User->save($this->request->data)){
            move_uploaded_file($this->data['User']['new_doc_file']['tmp_name'], $this->data['User']['doc_file']);
    
            $this->Session->setFlash('User is created');
            $this->redirect(array('action'=>'index'));
        } else {
            $this->Session->setFlash('Cannot register a user');
        }
    }
    

    (ie. upload the file with a temporary field name, manually add the doc_file field to the post array before you try to save).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning cakePHP 1.26. I got some sample data in a Table Testing
I am doing an e-learning application using CakePHP. The problem is that I need
I am learning cakephp by myself. I tried to create a user controller with
I am learning cakephp. can someone explain me what this is for $this->RunFunction->bindModel(array('belongsTo'=>array('Audio','Image','Video'))); where
I'm learning cakephp for some time and it's very nice, I'm using the cake
I'm learning CakePHP, my first MVC, and I have a few best practice questions.
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I am learning cakephp, and I was just doing a simple Todo list app
I am learning cakephp in an autodidact manner and I am a complete newbie
I am learning cakePHP, everything seems alright except that I am very confused of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.