How could I deal with a Folder Manager?

Hello guys!

I need my controller to manage my remote directories.

Should I create a component?

I used to do it with CakePHP but I want to do it using Yii.

A suggestion to my own question : http://blog.walterebert.com/

Has someone an idea? Opnion?

Do you mean to upload new files, deleting files, moving files, etc.? It is better to be implemented in terms of a controller with suitable actions.

Yes. However for uploading I am using File Upload class. I wish I could create a particular directory to put my files.

Example:




			if($model->save()) 

			{

				$folder = New Folder;

				$folder->create("\Path\images\{$model->id}\");

				if(is_uploaded_file($_POST['form']['image_url']))

				{

					$model->foto_url = CUploadedFile::getInstance($model,'image_url');

					if($model->image_url->hasError)

					{

						$model->image_url->saveAs($folder->path);

					}

				}

				$this->redirect(array('admin'));

			}

I have created a class Folder inside components path and I am using it as in the example.

Is it the better way to do in Yii?

Thanks for your answer.

I’ve written a component to extend CFileHelper…I called it SFileHelper…as follows:

<?php

class SFileHelper extends CFileHelper{

public static function deleteFile(&#036;path){


    return unlink(&#036;path);


}








public static function extractZipFile(&#036;zipFile,&#036;pathToSave){





    &#036;zip = new ZipArchive();


    if (&#036;zip) {


        if ((&#036;zip-&gt;open(&#036;zipFile)) &amp;&amp; (&#036;zip-&gt;extractTo(&#036;pathToSave))){


            &#036;zip-&gt;close();


            return true;


        }


    }


    return false;


    


}








public static function createDir(&#036;path, &#036;recursive){


    if (&#33;is_dir(&#036;path)) {


        return @mkdir(&#036;path, 0755, &#036;recursive);


    }


    return false;


}








public static function renameFile(&#036;oldName, &#036;newName){


    if (file_exists(&#036;oldName))


        return rename(&#036;oldName,&#036;newName);





    return false;


}





public static function deleteDir(&#036;dirName){


    if (is_dir(&#036;dirName))


        &#036;dir_handle = opendir(&#036;dirName);





    if (&#33;&#036;dir_handle)


        return false;





    while(&#036;file = readdir(&#036;dir_handle)) {


        if (&#036;file &#33;= &quot;.&quot; &amp;&amp; &#036;file &#33;= &quot;..&quot;) {


            if (&#33;is_dir(&#036;dirName.&quot;/&quot;.&#036;file))


                unlink(&#036;dirName.&quot;/&quot;.&#036;file);


            else


                self::deleteDir(&#036;dirName.'/'.&#036;file);


        }


    }





    closedir(&#036;dir_handle);


    rmdir(&#036;dirName);


    return true;


}

}

?>

I’m using it to manage my folders and to extract zip files…it’s not finished yet, but could help or inspire somebody to write something like this because Yii’s CFileHelper is really missing some features…

cheers!!

:>))

Thats great! Thanks :)