i have doubts on CAssetManager.

When use CAssetManager? the documentation says

"CAssetManager is a Web application component that manages private files (called assets) and makes them accessible by Web clients. "

But a simple image is private file? o for show simple image i have to use /protected/myfolder?

i try to use CAssetManager, and i save the image in /protected/myfolder, and save with CAssetManager in Assets, and retrieve the link for show my image.

But whenever i reload the page, or upload the new image, Yii create a new folder with the same file in assets…Can i create the folder only when i upload a new image??


If you just have images that you want to display, place them in webroot.

To understand the assetmanager, check


If i want show the image of my Site i use web root ( /protected/upload) right? but for show images, i have to modify the .htaccess ?

If i develop for example a widget i have to use CAssetManager?

/protected/upload is not good place for images you wish to show on page. ‘protected’ directory should be protected from direct web access and by default it is protected by .htaccess configuration. Rather put your files in /upload (where / is the root application directory with index.php).


i will make the directory with 777 permission…

When i have to use CAssetManager? When there is the danger of conflict file? or when i want make Widget ?

(sorry for my english :) )

you should use AssetManager when you develop Widget or other component which requires js/css/image files. Such component is placed in protected folder without direct access and you have decision: to put those static files in public directory, but then they will be in other disk location and such component will be hard to reuse in other project (you have to remember to copy all files from other locations and even remember what are those locations: /css, /js, /images, etc…) or you can keep static files near component class (in subdirectory for example) but you need to serve them somehow to end users when component is used on page. In this second case you use AssetManager to publish (copy) static files from directory protected from direct access to the public asset folder.

Is this clear enough?

Thank you now it’s more clear…

now try to copy my file in upload

i write



but i have an error

move_uploaded_file(/yiiTest/testdrive/uploads/photo.jpg): failed to open stream: No such file or directory

i must write only uploads/

Yii::app()->baseUrl is for making URLs… for directory on disk use Yii::app()->basePath

thanks, but


the path is /var/www/yiiTest/testdrive/protected, and my files are outside the protected