00001 <?php
00032 class Files {
00033
00034 const ICON_SUFFIX = "_icon";
00035 const THUMB_SUFFIX = "_thumb";
00036 const SMALL_SUFFIX = "_small";
00037 const MIDDLE_SUFFIX = "_mid";
00038
00045 public static function getFilePathFromId($id) {
00046 global $cfg;
00047
00048 $sql = "SELECT f.codename AS codename, c.id_owner AS id_owner " .
00049 "FROM files AS f LEFT JOIN content AS c ON f.id = c.id " .
00050 "WHERE (f.id = " . $id . ") AND (c.id_area = " . $cfg->getAreaId() . ")";
00051 $res = mysql_query($sql);
00052 if ($res === FALSE) { return ""; }
00053
00054 if (mysql_num_rows($res) > 0) {
00055 $line = mysql_fetch_assoc($res);
00056 }
00057 mysql_free_result($res);
00058 if ($line['codename']) {
00059 return $cfg->getConfig("FILES_ROOTDIR") . $line['id_owner'] . "/" . substr($line['codename'], 0, 1) . "/" . $line['codename'];
00060 } else {
00061 return "";
00062 }
00063 }
00064
00072 public static function delete($id) {
00073 if ($filepath = Files::getFilePathFromId($id)) {
00074 @unlink($filepath);
00075
00076 @unlink($filepath . Files::ICON_SUFFIX);
00077 @unlink($filepath . Files::THUMB_SUFFIX);
00078 @unlink($filepath . Files::MIDDLE_SUFFIX);
00079 @unlink($filepath . Files::SMALL_SUFFIX);
00080 }
00081 }
00082 }
00083 ?>