I am working on to extract pdf files from site to the FTP. Currently, all my files along with a index file with the names of the files extracted is being generated into one folder. I want to divide this folder into multiple folders. Each Folder will contain 10 files each with the index file that has the names of these 10 files. So, Lets say I have 100 files, there will be 10 folders generated along with index file for each folder.
$currentFolder = $extractionFolderPath . $extractionFolderName . '/' . 'all-files';
if (!is_dir($currentFolder)) {
$oldmask = umask(0);
mkdir($currentFolder, 0777, true);
umask($oldmask);
}
//Start generating the PDF
if (!file_exists($currentFolder . "/" . $fileListResult['FILE_NAME']) || $overwriteExistingFiles == 1) {
//Append to the log files
if (file_exists($currentFolder . "/" . "index" . "1.csv")) { //log exists
$logContents = file_get_contents($currentFolder . "/" . "index" . "1.csv");
//print_r($logContents);
if (strpos($logContents, $fileListResult['FILE_NAME']) === false) {
$myLogFile = $currentFolder . "/" . "index" . "1.csv";
$fp = fopen($myLogFile, 'a');
$csvData = array($fileListResult['Name'],$fileListResult['FILE_NAME']);
fputcsv($fp, $csvData);
fclose($fp);
}
} else { //log not exist, just create and add
$myLogFile = $currentFolder . "/" . "index" . "1.csv";
// $fh = fopen($myLogFile, 'w');
$csvData = array($fileListResult['Name'],$fileListResult['FILE_NAME']);
$isNew = (file_exists($myLogFile) || is_file($myLogFile)) ? false : true ;
touch($myLogFile); //Sets access and modification time of file and If the file does not exist, Create it.
$fp = fopen($myLogFile, 'w');
if($isNew) //Add header Information if its new
{
fputcsv($fp , array ('Surname,File Name'));
}
fputcsv($fp, $csvData);
fclose($fp);
}
//Generate the file
$myFile = $currentFolder . "/" . $fileListResult['FILE_NAME'];
$fh = fopen($myFile, 'w');
fwrite($fh, $pdfcontent);
fclose($fh);
How can i amend this code?