I was trying to figure out a Yii way to handle file upload. The regular single file upload is well taken care of by Form and CFileUpload, however when I try to implement a multiple file upload using CMultiFileUpload and CUploadedFile, things become ugly.
I started with the simplest way, no form required, I have a view like
in controller, I use $_FILES['uploadfile'] to get the uploaded file array, which is fine. however, I couldn't find a way to pass to CUploadFile, which has only getInstance () and getInstanceByName() motheds, none of them seems fit the situation here. ( getInstance () only works with form, while getInstanceByName() seems only works with single upload).
I am not sure if I miss sth there, so any advice is welcome.
This is based on the jQuery Multi File Upload plugin. The uploaded file information can be accessed via $_FILES[widget-id], which gives an array of the uploaded files. Note, you have to set the enclosing form’s ‘enctype’ attribute to be ‘multipart/form-data’.
actually, you can only access uploaded file information via $_FILES['inputfiled_name'], NOT $_FILES[widget-id].
@qwerty : If you check the CMultiFileUpload class reference, you will see CMultiFileUpload is bridge class for jqueryMultipleFile plugin.
@StErMi : Though my original attempt is to make CMultiFileUpload work with CUploadedFile, I gave the cookbook example a try, however it has many typos among other issues, I have left a comment there. Basically, I cannot get the file info in $_POST.
The class of $imageModel object does not need to have ‘files’ attribute (i think it wouldn’t be of much use, unless you tweak model). I like this approach since files are uploaded inside $_FILES[model_class_here][files] and there is no bare ‘files’ key in $_FILES.