Skip to content

Commit

Permalink
Fix enable first download to populate array
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Sylvester committed Jun 25, 2020
1 parent b76768c commit 054c261
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
84 changes: 41 additions & 43 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,55 +80,53 @@ function getFileExt($fname)
$downloads = unserialize(fread($file,filesize("$path/resources/log")));

fclose($file);

// Check if the key or filename already is in the array else append it
if (array_key_exists($fname, $downloads))
{
$downloads[$fname] += 1;
}
else
{
$downloads[$fname] = 1;
}

// Massive debug code to figure out why this constantly overwrites with bad data

$debugfile = "$path/resources/log".time();

//touch($debugfile);
//$file = fopen($debugfile,"w");
//fwrite($file,serialize($downloads));
//fclose($file);

if ($downloads != null && $downloads != "" && $downloads != " " && count($downloads) != 0)

try
{
// Check if the key or filename already is in the array else append it
if (array_key_exists($fname, $downloads))
{
$downloads[$fname] += 1;
}
else
{
$downloads[$fname] = 1;
}

// Massive debug code to figure out why this constantly overwrites with bad data

$debugfile = "$path/resources/log".time();

//touch($debugfile);
//$file = fopen($debugfile,"w");
//fwrite($file,serialize($downloads));
//fclose($file);


try
{
$file = fopen("$path/resources/log","w");

}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}

try
{
fwrite($file,serialize($downloads));
}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}
$file = fopen("$path/resources/log","w");

}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}

try
{
fwrite($file,serialize($downloads));
}
catch (Exception $e)
{
$file = fopen("$path/resources/logerror","w");
fwrite($file,$e->getMessage()."\n");
fclose($file);
}

fclose($file);


}


Expand Down
11 changes: 11 additions & 0 deletions resources/DirectoryLister.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public function __construct() {
die('ERROR: Missing application config file at ' . $configFile);
}

// Remove default config if present
$defaultConfig = $this->_appDir . '/default.config.php';

if (file_exists($defaultConfig)) {
die('ERROR: Please configure the application by renaming default.config.php inside /resources to config.php and configuring the application parameters within!');
}

// Load the log file
$log = $this->_appDir . '/log';

Expand All @@ -66,6 +73,10 @@ public function __construct() {
} else {
touch($log);
}

if (filesize($log) <= 0) {
$this->setSystemMessage('error', '<b>ERROR:</b> Log file empty!');
}

// Set the file types array to a global variable
$this->_fileTypes = require_once($this->_appDir . '/fileTypes.php');
Expand Down

0 comments on commit 054c261

Please sign in to comment.