Hi all,
I am currently developing an upload feature for my application. I want to create photo album (no problem) and populate these albums with a form like this:
[DropdownAlbum]
[FileuploadField]
For the upload I use Plupload (http://www.plupload.com) which lets me upload several images at once. Here is my Photo.php:
/* The form gets submitted after all files have been uploaded */
public function actionCreate()
{
$model=new Photo;
if(isset($_POST['Photo']))
{
// this variable contains how many images were uploaded
$length = (int) $_POST['counter_upload'];
for ($i = 0; $i < $length; $i++) {
$model = new Photo;
$model->path = $_POST;
$model->attributes = $_POST['Photo'];
$model->save();
}
$this->redirect(array('index'));
}
$this->render('create',array(
'model'=>$model,
));
}
/* This action is called for every single file that gets uploaded */
public function actionUpload() {
$uploadedFile = CUploadedFile::getInstanceByName('file');
$uploadedFile->saveAs('photos' . DIRECTORY_SEPARATOR . $uploadedFile->getName());
}
So this is what happens if I want to add 2 Pictures to an album:
-
actionCreate() - Show form
-
Fill in Album name + select two files to upload
-
actionUpload() for file1 is called
-
actionUpload() for file2 is called
-
actionCreate() is called an $_POST is filled
My problem is that I somehow need to communicate between these 2 methods. I have actionUpload() which only has access to $_FILES and actionCreate() which only has access to $_POST, but I need both in order to set the correct album for each of the photos.
Anyone has ideas how to solve this without writing into temp files or something like that?