savecakephp-2.4

CakePHP SaveAll filename


When I'm trying to use the saveAll function, it's not saving properly when there's an image uploaded to the data.

$this->Deal->saveAll($this->request->data);

Here's an example of data that's working:

array(2) {
  ["Resort"]=>
  array(8) {
    ["resort"]=>
    string(4) "Test"
    ["rating"]=>
    string(3) "4.0"
    ["image_link"]=>
    string(0) ""
    ["trip_advisor"]=>
    string(12) "123123123123"
    ["image"]=>
    string(0) ""
    ["deal_id"]=>
    string(3) "258"
    ["id"]=>
    string(3) "245"
    ["filename"]=>
    array(5) {
      ["name"]=>
      string(0) ""
      ["type"]=>
      string(0) ""
      ["tmp_name"]=>
      string(0) ""
      ["error"]=>
      int(4)
      ["size"]=>
      int(0)
    }
  }
  ["Deal"]=>
  array(1) {
    ["id"]=>
    string(3) "258"
  }
}

Here's an example of data that's not working:

array(2) {
  ["Resort"]=>
  array(8) {
    ["resort"]=>
    string(4) "Test"
    ["rating"]=>
    string(3) "4.0"
    ["image_link"]=>
    string(40) "http://google.com"
    ["trip_advisor"]=>
    string(6) "123123"
    ["image"]=>
    string(0) ""
    ["deal_id"]=>
    string(3) "258"
    ["id"]=>
    string(3) "245"
    ["filename"]=>
    array(5) {
      ["name"]=>
      string(12) "logo.png"
      ["type"]=>
      string(9) "image/png"
      ["tmp_name"]=>
      string(14) "/tmp/phpZtCTVC"
      ["error"]=>
      int(0)
      ["size"]=>
      int(3702)
    }
  }
  ["Deal"]=>
  array(1) {
    ["id"]=>
    string(3) "258"
  }
}

Update

It's not only not saving, it's simply returning nothing. I get an empty page when I try the var_dump:

var_dump($this->Deal->saveAll($this->request->data));

Also, there's no error in the error_log.

Update 2

After digging further, I found out it was an issue of memory limit so I've updated the limit and now I get the error:

Can not determine the mimetype.

From what I see in the Validation class of CakePHP, it's trying to get the mime type of the tmp_name which is /tmp/phpZtCTVC and it seems like it can't get it so it's throwing an exception.


Solution

  • Turns out the problem was that the php extension fileinfo was not enabled.

    Just did a recompile of php with the extension and everything worked fine after that. :)