I can't seem to write multiple fwrites to an error log I set up; only $time gets written to the file. What am I missing here?
error_reporting(E_ALL);
if (@(include 'recursive_directory_scan_comments.php') === FALSE) {
//echo "Included";
include 'recursive_directory_scan_comments.php';
}//end if
if (@(include '../db/connect.php') === FALSE) {
//echo "Included";
include '../db/connect.php';
}//end if
if ((include 'error.php') === FALSE) {
//echo "Included";
include 'error.php';
}//end if
/* **************************
LOG FUNCTIONALITY
***************************** */
//set up logfile
$logfile = "uploadImages.txt";
$logdir = "../logs/";
$log = $logdir . $logfile;
//set up DB table for images
$imagesTable = "images";
//set up images path
$pathImages = "../images/listings";
//prepare for writing to log file
$output = fopen($log, 'w');
if(!file_exists($logdir)){
//if logdir doesn't exist and user wants a log, create the directory
$makedir = mkdir($logdir, 0700);
if (!$makedir) { //if can't make directory
$msg = "Hey, something's happened to the logs directory, ";
$msg .= $logdir;
$msg .= ". I couldn't recreate the directory.";
$msg .= "\nPlease check things out.";
//echo $msg;
//exit;
//mail($to, $subject, $msg, $headers);
return FALSE;
} else {
$msg = "Hey, something's happened to the logs directory, ";
$msg .= $logdir;
$msg .= ". I recreated the directory, but you may want to check things out.\n";
//echo $msg;
//open log for writing
//write time to log
fwrite($output, "\n******".$time."******\n");
}
} elseif(file_exists($logdir)) {
//open log for writing
// write time to log
//echo "BLAH";
fwrite($output, "\n******".$time."******\n");
}
/* **************************
END LOG FUNCTIONALITY
***************************** */
//empty the table
$sql="TRUNCATE TABLE $imagesTable";
//echo $sql."<BR />";
mysql_query($sql);
//get the columns from the respective tables
$resultImages = mysql_query("SHOW COLUMNS FROM $imagesTable",$db);
if (!$resultImages) {
die('Invalid query: ' . mysql_error());
$msg = "Query failed: " . mysql_error() . "\n";
fwrite($output, $msg);
}
//start putting table fields into array
$imageFields = array();
while ($rowImages = mysql_fetch_assoc($resultImages)) {
$imageFields[] = $rowImages["Field"];
}
//implode the table fields in preparation for our dynamic INSERT query
$imageFields = implode(",",$imageFields);
/*
---------------------------------------
Find out what files are in directories
---------------------------------------
*/
# get all files and directories in an array
$filestructureImages = scan_directory_recursively($pathImages);
/*
----------------------------------------------------------------------------------------------------
This portion reads through images directory,
gets CONTENT arrays from $filestructureImages
and dumps into database with designated field names
----------------------------------------------------------------------------------------------------
*/
foreach($filestructureImages as $key => $value){
foreach($value as $key2 => $val){
if($key2 == 'content') {
$path = $value['path'];
$filestructure = scan_directory_recursively($path);
foreach($filestructure as $key3 => $val3){
$name = $val3['name'];
$path = $val3['path'];
$type = $val3['extension'];
$size = $val3['size'];
// Insert information into the table "images"
// only if image size is > 0; otherwise, don't bother...
// we don't want people searching on broken images anyway
if ($size > 0) {
$sql2 = "INSERT INTO $imagesTable ($imageFields) VALUES('NULL', '$name', '$path', '$type', '$size');";
mysql_query($sql2) or die("Failed Query of " . $sql2);
//echo $sql2."<BR />";
if (die) {
$msg = "Insert failed: " . $sql2 . "\n";
fwrite($output, $msg);
} else {
$msg = $sql2 . "\n";
fwrite($output, $msg);
}
} // END size > 0
} // END foreach($filestructure as $key3 => $val3)
} // END if($key2 == 'content') {
} // END foreach($value as $key2 => $val){
} // END foreach($filestructureImages as $key => $value)\
if($output){
fclose($output);
}