Create file and directory
public function createfileanddir() {Get content from file and directory
$directoryname = 'directoryname';
$filename = 1;
$directory = APPPATH . 'uploads/cache/'.$directoryname;
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
$file = APPPATH . 'uploads/cache/'.$directoryname.'/'.$filename.'.json';
if (file_exists($file)) {
unlink($file);
}
if (!file_exists($file)) {
$settings = [
'settings'=>[],
'socialSettingsArr'=>[],
'pageSettings'=>[],
];
$fh = fopen($file, 'w');
fwrite($fh, json_encode($settings));
fclose($fh);
}
}
public function getfiles() {
$directoryname = 'directoryname';
$directory = 'uploads/cache/'.$directoryname;
$files = array_diff(scandir($directory), array('.', '..'));
if(count($files) > 0){
foreach ($files as $file):
$file = $directory . '/'.$file;
$storedata = file_get_contents($file);
$storedata = json_decode($storedata, true);
echo '<pre>';print_r($storedata);
endforeach;
}
}