Hi guys.
I am having a problem. I have two tables projects and attachments with 1 project can have many attachments. Now I have created CRUD for project and its working fine… But i made some changing in project form for adding multiple attachments.
Now i am using CMultifileUpload to create a queue of files… when form is submitted i do this.
public function actionCreate()
{
$model = new Projects;
if (isset($_POST['Projects']))
{
$model->attributes = $_POST['Projects'];
if ($model->save())
{
/* Created Project ID */
$project_id = $model->id;
/* Upload Attachments */
$model->uploadAttachments($project_id);
/* Go to view */
$this->redirect(array('view', 'id' => $project_id));
}
}
$this->render('create', array(
'model' => $model,
));
}
Before redirecting i call this method $model->uploadAttachments($project_id); for uploading all attachments.
and in this method
public function uploadAttachments($project_id)
{
/* path */
$path = "uploads/attachments";
/* read file array */
foreach ($_FILES['files']['name'] as $key => $filename)
{
/* upload it */
if(move_uploaded_file($_FILES['files']['tmp_name'][$key], $path . '/' . $filename))
{
//here i want to insert filename in attachments table with project id
}
}
//echo 'Alpha';
}
inside if i want to insert filename in attachments table with project id with active records…
Any idea ?