Otóż mam klasę, która odpowiada za uploadowanie zdjęcia na serwer i przesłaniu do mysqla o tym informacji, za to odpowiada klasa napisania poniżej, ale niestety nie działa, kiedy przesyłam plik za pomocą formularza, wyskakuje po prostu białe tło, plik nie został dodany, a w mysqlu nie pojawiła się informacja. Proszę o nakierowanie na to co zrobiłem źle.
class.Uploader.php
<?php class ImageUploader { var $name; var $type; var $size; var $temp; var $image; var $blad; var $max_rozmiar; var $category; function init() { $this -> blad = $_FILES['userfile']['error']; if($this -> blad != 0) { $error = 'PHP zwrócił następuący błąd: '.$this -> blad; return FALSE; } $this -> name = $_FILES['userfile']['name']; $this -> type = $_FILES['userfile']['type']; $this -> size = $_FILES['userfile']['size']; $this -> temp = $_FILES['userfile']['tmp_name']; /* 1 */ $this -> max_rozmiar = 8192; return TRUE; } function validate() { if($this -> type !='image/gif' && $this -> type !='image/pjpeg' && $this->type !='png') /* 2 */ { $error ="To nie jest poprawny format obrazka (dopuszczalne rozszerzenia gif,jpg,jpeg,png)"; return FALSE; } if($this -> size >= $max_rozmiar) { $error= "Plik jest za duży. Dopuszczalny rozmiar to: $max_rozmiar"; return FALSE; } if($rozmiar[1]>2560 || $rozmiar[2]>1280) { $error = 'Wgrywanie tego zdjecia może trochę potrwać... Czekaj...'; return TRUE; } return TRUE; } function savefile($id) { { $error = 'Nie można otworzyć pliku z katalogu tymczasowego'; return FALSE; } $db -> query("INSERT INTO zdjecia ('byte', 'image_type', 'category') VALUES('".$this -> image."','".$this -> type."','".$this -> category."'"); return TRUE; } } ?>
upload.php
<?php require_once ("config.php"); require_once ("class.Uploader.php"); $db = @new db($host, $nazwabazy, $user, $pass); if($img -> init()) { if($img -> validate()) { if($img -> savefile()) { } } } ?>
dla formalnośći index.html
<form action="upload.php" method="post" enctype="multipart/form-data" accept="image/gif, image/jpeg, image/png"> <input type="hidden" name="MAX_FILE_SIZE" value="8192"> Dodaj zdjecie: <input name="userfile" type="file"> <br /><input type="submit" value="Wgraj"> </form>
Pozdrawiam,
Ravik