function rawlog($message, $type = 's', $loc = "") { global $config; // First determine the name of the current log file. The name is // based on time. $t = UnixTimeNow(); $fbase = "log_" . date("ymd", $t) . ".txt"; $filename = $config["LogDir"] . $fbase; $newfile = !file_exists($filename); $logfile = fopen($filename, "a+"); if ($newfile) { // New file. Write info at top. $line = "#" . date("m/d/Y l") . ' ' . $config["ServerName"] . "\n"; fwrite($logfile, $line); } // Make sure message is an array of lines, and that embedded new-lines are // converted into array elements. $msglines = log_fixmsg($message); // Now, format the first line... $firstline = $msglines[0]; array_shift($msglines); if (empty($type)) { $type = 's'; } $line = '*' . date("H:i:s") . ' ' . substr($type, 0, 1); $line .= sprintf("%3d", GetUserID()); if (empty($loc)) { $page = basename($_SERVER["SCRIPT_NAME"]); } else { $page = $loc; } if (!empty($page)) { $line .= ' ' . $page; } $line .= '> ' . $firstline . "\n"; fwrite($logfile, $line); foreach ($msglines as $line) { fwrite($logfile, '+> ' . $line . "\n"); } fclose($logfile); }
function StorePicture($tempfile, $delete = true) { $loc = "piclib.php->StorePicture"; $tstart = microtime(true); // Time the entire operation... // Make sure all the directories exist. CheckPicDirs(); if (empty($tempfile)) { log_error($loc, "Empty temp file!"); return false; } if (!file_exists($tempfile)) { log_error($loc, "Temp file does not exists ( " . $tempfile . ')'); return false; } $imginfo = @getimagesize($tempfile); if ($imginfo === false) { log_error($loc, 'Pic file appears unreadable. Getimagesize() failed reading ' . $tempfile); return false; } $width = $imginfo[0]; $height = $imginfo[1]; $type = $imginfo[2]; if ($type != IMG_JPG) { log_error($loc, 'Pic file does not seem to be a jpg. Output of getimagesize = ' . print_r($imginfo, true)); return false; } if ($width < 10 || $height < 10) { log_error($loc, 'Invalid Width and/or Height sizes (' . $width . ', ' . $height . ') for ' . $tempfile); return false; } $filesize = @filesize($tempfile); if ($filesize === false) { log_error($loc, 'Unable to get the file size for ' . $tempfile); return false; } if ($filesize > 10000000) { log_error($loc, 'File size for picture is too big (>10MB). Size= ' . $filesize . ', tempfile= ' . $tempfile); return false; } // All seems okay... Lets create the database entry. $sql = 'INSERT INTO Pictures (DateOfUpload, FileStatus, FileSize, Width, Height) VALUES ('; $sql .= '"' . DateTimeForSQL(UnixTimeNow()) . '"'; // DateOfUpload $sql .= ', 0'; // FileStatus $sql .= ', ' . intval($filesize); // FilsSize $sql .= ', ' . intval($width); // Width $sql .= ', ' . intval($height); // Height $sql .= ')'; $result = SqlQuery($loc, $sql); $id = GetSqlConnection()->insert_id; // Now that we have the ID, we can put the picture in it's place, and resize it. // Copy the input to the 'orig' folder. $origfile = PicPathName($id, 'orig'); if ($delete) { $result = @rename($tempfile, $origfile); } else { $result = @copy($tempfile, $origfile); } if ($result === false) { log_error($loc, 'Unable to move/copy file from ' . $tempfile . ' to ' . $origfile . '.'); return false; } // Now that we have the original in place, all the others can be resized from it. $result = PicResizeAll($id, $width, $height); if ($result === false) { return false; } // Now that all the files are in their correct places, update the file status in // the database. $sql = 'UPDATE Pictures SET FileStatus=1 WHERE PicID=' . intval($id); $result = SqlQuery($loc, $sql); $telp = (microtime(true) - $tstart) * 1000.0; log_msg($loc, "Pic ID " . $id . " Successfully Stored on server. (Elp=" . sprintf("%6.2f", $telp) . " ms.)"); return $id; }