Difference between #1 and #4 of
Uploading multiple images with CMultiFileUpload

Changes

Title unchanged

Uploading multiple images with CMultiFileUpload

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

CMultiFileUpload, File upload, image, saveAs

Content changed

"The documentation for [CMultiFileUpload](http://www.yiiframework.com/doc/api/1.1/CMultiFileUpload/ "CMultiFileUpload") isn't clear!" "I don't know where the uploaded files went!" "How can I save those files I uploaded in the right directory!" "!@!##!!!!"

I understand your pain.
[...]
```php
// make the directory to store the pic:
                if(!is_dir(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'. $model->name)) {                   mkdir(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'. $model->name))                   chmod(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'. $model->name)), 0755);
 
   
// the default implementation makes it under 777 permission, which you could possibly change recursively before deployment, but here's less of a headache in case you don't                 }

```
[...]
foreach ($images as $image => $pic) {
echo $pic->name.'<br />';
if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'.$
modelpic->name)) {
// add it to the main model now
$img_add = new Picture();
[...]
```

Obviously, you have to handle the errors, but that's up to you (I haven't coded that yet). However, now you have the files uploaded to your model, and you can play around with it

 
 
Hat-tip: **Wiseon3** caught a copy/paste error of mine:
 
 
 
 
```php 
"if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'. $model->name)) {
 
               // add it to the main model now"
 
```
 
 
has been updated to
 
 
 
 
```php 
if ($pic->saveAs(Yii::getPathOfAlias('webroot').'/images/ADD YOUR PATH HERE!/'. $pic->name)) {
 
                        // add it to the main model now
 
```
 
 
The main code has been updated to reflect this change. Thanks
33 0
38 followers
Viewed: 129 842 times
Version: 1.1
Category: How-tos
Written by: rsingh
Last updated by: Maurizio Domba Cerin
Created on: Apr 15, 2011
Last updated: 13 years ago
Update Article

Revisions

View all history