Im working on a site that will enable me to upload files to the server, Im trying to get the file to be renamed to the corresponding mysql id that is inserted with the information.
It kind of works, but every time I upload a file it will re-write over the last file that was uploaded.
This is my code
function uploadFile() {
$file = $this->data['Upload']['file'];
$pid = mysql_insert_id();
if ($file['error'] === UPLOAD_ERR_OK) {
if (move_uploaded_file($file['tmp_name'], APP.'webroot/files/uploads'.DS."$pid.mp4")) {
$this->data['Upload']['name'] = $file['name'];
$this->data['Upload']['eventname'] = $file['evetname'];
$this->data['Upload']['description'] = $file['description'];
return true;
}
}
return false;
}
These are the errors that are occuring on my site,
Notice (8): Indirect modification of overloaded property UploadsController::$data has no effect [APP/Controller/uploads_controller.php, line 58]
Notice (8): Undefined index: eventname [APP/Controller/uploads_controller.php, line 59]
Notice (8): Indirect modification of overloaded property UploadsController::$data has no effect [APP/Controller/uploads_controller.php, line 59]
Notice (8): Undefined index: description [APP/Controller/uploads_controller.php, line 60]
Notice (8): Indirect modification of overloaded property UploadsController::$data has no effect [APP/Controller/uploads_controller.php, line 60]
I don’t quite get what is going on really?
Also should I be using the mysqli_insert_id() function instead of mysql_insert_id()? I don’t really know how the mysqli_insert_id() works, any help please guys???
You’re trying to manipulate
$this->datawhich is read only in Cake 2.0. You should use the newCakeRequestobject introduced in Cake 2.0.So
$this->databecomes:$this->request->data.As for
mysql_insert_id(), I’m not sure where you are saving data to a database table. Cake stores theidof the last inserted record in$this->ModelName->id, so you could use that as well.