php - MongoDB Update GridFS Record -
i have implemented crud
operations using php + mongodb
. below code used upload file using gridfs
.
$conn = new mongoclient(); $db = $conn->selectdb('mydb'); $gridfs = $db->getgridfs('uploads'); foreach ($_files $file) { if(in_array($file['type'], $acceptedtypes)){ $id = $gridfs->storefile($file['tmp_name'], array('filename' => $file['name'], 'type' => $file['type'], "id"=> 13, "parentid" => "10", "title" => $file['name'], "isfolder" => 0)); }else{ echo 'file not of correct type'; } } $conn->close();`
i able upload document using above code, when try update title
of file not work. code update file name below.
$files = $db->fs->uploads; $primid = $_get['id_value']; $renametitle = $_get['name']; $updatedata = array("title" => $renametitle, "updateddate" => date('y-m-d')); $files->update(array("id" => $primid), array( '$set' => $updatedata )); $conn->close();
this update title
of file id
passed. code works if need update record not working gridfs
file upload.
to more precise if pass id
below,
$file = $gridfs->findone(array('id' => 13)); **//works** $file = $gridfs->findone(array('id' => $_get['id'])); **//do not works**
is there other method used in order update gridfs
records ?
thanks.
finally figured out.
mongodb needs integer
variable create right query.
if using $_get
or $_post
values directly, should first convert integer value. in project works :
$id = (int)$_get["id"]; $file = $gridfs->findone(array('id' => $id)); **//works charm**
hope helps someone.
Comments
Post a Comment