I'm new user on mongodb, I'm working with cakephp. I'm trying to test the cakephp's plugin from ichikaway. This plugin allow cakephp working with a mongodb (NoSql database). So, I'm wondering if someone have already tried to do an image upload with ?
Asked
Active
Viewed 305 times
0
-
Sorry can't see the question here? What have you tried and what difficulty is it that you are having? – Daniel Casserly Aug 13 '12 at 08:35
-
This is what I do in the case of Sql database: – Martial Assane Palm Aug 13 '12 at 08:52
-
So basically how to save an image in a database? This question has been asked many times and there are whole debates on this site alone about the issue. – Daniel Casserly Aug 13 '12 at 10:00
-
You have asked this question many times: http://stackoverflow.com/questions/11919616/add-a-image-file-in-mongodb-using-cakephp but maybe @DanielCasserly can link some of those questions for you to look at, I mjust admit I have trouble finding these "many" questions. – Sammaye Aug 13 '12 at 11:34
2 Answers
0
The cakephp-mongodb library does not seem to provide an API for interacting with GridFS. Your best bet is likely to use the MongodbSource::getMongoDb() method to obtain the MongoDB instance and then access the MongoGridFS classes directly. The PHP documentation includes several examples for storing files (including uploaded files) to GridFS.

jmikola
- 6,892
- 1
- 31
- 61
0
I try this and it works !
<?php
class ProductsController extends AppController {
public $name = 'Products';
public function add(){
if ($this->request->is('post')){
debug($this->request->data);
$dir = IMAGES.date('Y');
if (!file_exists($dir))
mkdir($dir);
$dir .= DS.date('m');
if (!file_exists($dir))
mkdir($dir);
$f = explode('.', $this->request->data['Product']['file']['name']);
$ext = '.'.end($f);
$filename = Inflector::slug(implode('.',array_slice($f,0,-1)),'-');
debug($ext);
debug($filename);
$data = array(
'name' => $this->request->data['Product']['name'],
'url' => date('Y').'/'.date('m').'/'.$filename.$ext
);
//debug($data);
if ($this->Product->save($data)){
move_uploaded_file($this->request->data['Product']['file']['tmp_name'], $dir.DS.$filename.$ext);
$id = $this->Product->getInsertId();
debug($id);
}
}
}

Martial Assane Palm
- 31
- 1