Tabela wygląda tak:
CREATE TABLE IF NOT EXISTS `sessions` (
`session_id` varchar(32) NOT NULL,
`session_start` int(11) unsigned NOT NULL,
`session_time` int(11) unsigned NOT NULL,
`session_value` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Wzięta z
http://wortal.php.pl/phppl/wortal/artykuly...i/implementacjeUdało mi się to zrobić

Zmieniłem klasę odpowiadającą za połączenie z bazą danych i sesji
[EDIT]chciałem wkleić tu kod ale był jakiś błąd, jakiś bo nie otrzymałem komunikatu co dokładnie jest nie tak

Dzisiaj znalazłem trochę czasu na stworzenie własnej klasy artykułów i mam jedno pytanie, czy tak może być
Oto kod:
class Articles {
function Display_Categories() {
$query = mysql_query("SELECT id, title FROM art_categories ORDER BY id ASC"); $categories[] = $row;
}
return $categories;
}
}
function Display_Category($id) {
$query = mysql_query("SELECT id, title, date, short_desc FROM articles WHERE cat=".intval($id)." ORDER BY id DESC"); $articles[] = $row;
}
return $articles;
}
}
function Display_Article($id) {
$query = mysql_query("SELECT id, title, date, long_desc, author FROM articles WHERE id=".intval($id).""); $article[] = $row;
return $article;
}
}
function Delete_Article($id) {
// sprawdzanie czy uzytkownik ma uprawnienia - to dac tutaj w funkcji czy gdzies na zewnatrz?
return true;
} else {
returne false;
}
} else {
returne false;
}
}
function Add_Article($id) {
// sprawdzanie czy uzytkownik ma uprawnienia - to dac tutaj w funkcji czy gdzies na zewnatrz?
$approved = 1;
} else {
$approved = 0;
}
$sql = "INSERT INTO articles (title, short_desc, long_desc, author, date, st) VALUES ('{$_POST['title']}', '{$_POST['short_desc']}', '{$_POST['long_desc']}', '{$_POST['author']}', '{$time}', '$approved')";
return true;
}
}
Cześć,
mam kolejny problem z klasą.
Chodzi o upload obrazków.
Mam taką klasę:
<?php
class Upload {
public $dir;
public $typ;
public $file_width;
public $file_height;
public $file_maxwidth;
public $file_maxheight;
public $file_name;
public $file_type;
public $file_size;
public $file_tempname;
public $file_error;
public $errors = array(); public $file_ext;
public $file_exts = array();
public static function UpFile
($file, $dir, $width=150
, $height=150
, $size=51200
) { $this->dir = $dir;
$this->file_exts=array('gif', 'jpg', 'jpeg', 'png', 'bmp'); $this->file_name = $_FILES[$file]['name'];
$this->file_type = strtolower($_FILES[$file]['type']); $this->file_size = $_FILES[$file]['size'];
$this->file_tempname = $_FILES[$file]['tmp_name'];
$this->file_error = $_FILES[$file]['error'];
$this->file_maxwidth = $width;
$this->file_maxheight = $height;
$this->file_width = $file_dimensions[0];
$this->file_height = $file_dimensions[1];
$this->errors[$file] = 'Nie udało się wgrać pliku na serwer';
if( $this->file_size > $size )
$this->errors[$file] = 'Za duży rozmiar pliku';
if( !in_array($this->file_ext, $this->file_exts) ) $this->errors[$file] = 'Zły format pliku';
}
public static function upload_photo
() { $photo_dest = $this->dir;
$width = $this->file_width ;
$height = $this->file_height;
if( $height > $this->file_maxheight )
{
$width = floor($width * $this->file_maxheight / $height); $height = $this->file_maxheight;
}
if( $width > $this->file_maxwidth )
{
$height = floor($height * $this->file_maxwidth / $width); $width = $this->file_maxwidth;
}
// RESIZE IMAGE AND PUT IN USER DIRECTORY
switch($this->file_ext)
{
case "gif":
$file = imagecreatetruecolor($width, $height);
$new = imagecreatefromgif($this->file_tempname);
$kek=imagecolorallocate($file, 255, 255, 255);
imagefill($file,0,0,$kek);
imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
imagejpeg($file, $photo_dest, 100);
ImageDestroy($new);
ImageDestroy($file);
break;
case "bmp":
$file = imagecreatetruecolor($width, $height);
$new = $this->imagecreatefrombmp($this->file_tempname);
for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
imagejpeg($file, $photo_dest, 100);
ImageDestroy($new);
ImageDestroy($file);
break;
case "jpeg":
case "jpg":
$file = imagecreatetruecolor($width, $height);
$new = imagecreatefromjpeg($this->file_tempname);
for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
imagejpeg($file, $photo_dest, 100);
ImageDestroy($new);
ImageDestroy($file);
break;
case "png":
$file = imagecreatetruecolor($width, $height);
$new = imagecreatefrompng($this->file_tempname);
for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height);
imagejpeg($file, $photo_dest, 100);
ImageDestroy($new);
ImageDestroy($file);
break;
}
chmod($photo_dest, 0777);
return true;
}
}
?>
Dostaję taki komunikat:
Fatal error: Using $this when not in object context in
upload.class.php on line
21Klasę wywołuję tak:
$photo = new Upload();
$file = '/Upload/avatar/'.time().'_'.$_FILES['avatar']['name']; $photo->UpFile('avatar', $file);
if (sizeof($photo->errors) == 0
) { $photo->upload_photo();
}
proszę o pomoc