Why don't you just use a post_system
hook? It's called after the final page is sent to the browser, that way you can load views normally, without echoing them out.
Here's an example controller:
class Home extends Controller {
function index()
{
$this->move_audio = TRUE;
$this->old_folder = "/path/to/folder/";
$this->new_folder = "/path/to/folder2/";
$this->load->view("some_view");
}
}
And an example hook:
function post_system()
{
$CI =& get_instance();
if( isset($CI->move_audio) && $CI->move_audio === TRUE)
{
// Trim, then add trailing slash for consitency
$old_folder = rtrim($CI->old_folder, "/")."/*.mp3";
$new_folder = rtrim($CI->new_folder, "/")."/";
exec("mv {$old_folder} {$new_folder}");
}
}
Check out the hooks user guide for info on setting them up. They are your friends!
EDIT: Something I just thought of...
If you're only going to be doing this inside one controller method... it would probably be better to use Phil's approach. This would avoid having a hook call for every request which would be unnecessary if you only need it once.
Another thing you could do, if you only need it once, is use CI's _output()
handler for Controllers (info here). That would work like this:
class Home extends Controller {
// Initalize the var to avoid having to
// check if it's set or not
var $move_audio = FALSE;
// CONTROLLER METHOD
function index()
{
$this->move_audio = TRUE;
$this->old_folder = "/path/to/folder/";
$this->new_folder = "/path/to/folder2/";
$this->load->view("some_view");
}
// OUTPUT HANDLER
function _output($output = "")
{
echo $output;
if($this->move_audio === TRUE)
{
// Trim, then add trailing slash for consitency
$old_folder = rtrim($this->old_folder, "/")."/*.mp3";
$new_folder = rtrim($this->new_folder, "/")."/";
exec("mv {$old_folder} {$new_folder}");
}
}
}