class mytest extends Controller {
public function index(){
//CREATE A FILE
//generate random filename
$hash = strtoupper(md5(rand()));
$random_name = substr($hash, rand(0, 22),8);
//get random file from directory
$list = openDerictory("someplace/sdfs");
$randomFile = $list[array_rand($list)];
appendToFile("someplace/sdfs",$randomFile, $random_name);
///DO RANDOM THINGS
var $t = 'sdfs';
foreach($list as $item){
echo $t . $item;
}
//LET THE USER KNOW SOMETHING
echo "this is a test";
echo "we did somtyhing";
echo "try something else";
}
//Function to open Directory
function openDerictory($path, $type= ".txt")
{
$list = array();
if ($dh = opendir($path)) {
$count = 0;
while (($file = readdir($dh)) !== false) {
$info = pathinfo($path . $file);
if(strtolower($info['extension']) == strtolower($type)){
$list[$count] = $file;
$count++;
}
}
closedir($dh);
}
return $list;
}
function appendToFile($path ,$randomFile, $random_name)
{
//get contents
$file = file_get_contents($path . $randomFile, FILE_USE_INCLUDE_PATH);
//savefile
$fp = fopen($path . $random_name . 'ext','a');
fwrite($fp, $file);
fclose($fp);
}
}