Mam strone na serwerach cba i friko o adresach http://chenoveth.cba.pl i http://www.chenoveth.za.pl Umie¶ciłem w niej skrypt umożliwiaj±cy dodawanie obrazków (tylko w formacie jpg/jpeg i gif). Działanie skryptu polega na tym że w momencie dodania pierwszego obrazku (pierwszego obrazku do skryptu w ogóle) zostanie wygenerowany folder o nazwie uploads. Następnie w nim zostanie wygenerowany kolejny folder o unikalnej nazwie nadanej przez skrypt (ze znaków 1-9 i a-z np:jk6k8a12). W tym wła¶nie folderze zostanie umieszczony obrazek dodany przez użytkownika również o unikalnej nazwie nadanej przez skrypt (ze znaków 1-9 i a-z np:g8vlm.jpg) i wygenerowana będzie kopia tego obrazku (również w tym folderze co uploadowany obrazek; jk6k8a12 ) w innych rozmiarach np: 250x250px o nazwie w tym przypadku: thumb_g8vlm.jpg. W przypadku kolejnego dodania obrazku proces się powtarza. W utworzonym już folderze głównym uploads zostanie wygenerowany kolejny folder o unikalnej nazwie gdzie umieszczony bedzie dodany przez użytkownika obrazek (i dodana do niego unikalna nazwa) i jego wygenerowana kopia. Na komputerze domowym localhoscie działa to idealnie ale na serwerach cba i friko nie. Na serwerze cba nie może utworzyć kopii obrazku. Tworzy folder główny uploads tworzy foldery w nim zawarte i umieszcza w nich dodawane obrazki ale nie może utworzyć kopii tych obrazków. Natomiast na serwerze friko nawet nie tworzy głównego katalogo uploads. Nie wiem czy to jest wina skryptu czy może ustawień tych serwerów.
Skrypt ten wygl±da tak:
<?php class CustomException extends Exception{} class add_model extends Model { private $_errors; private $_token; //Form token private $_rootDir; //Main folder for our uploads private $_imgName; //Image name randomly generated private $_imgDest; //Direct file location on server private $_folderName; //Folder name randomly generated private $_folderPath; //Include root dir private $_thumbWidth; private $_thumbHeight; private $_thumbPrefix; private $_thumbDest; private $_fileName; private $_fileTemp; private $_fileSize; private $_fileType; private $_fileExt; private $_desc; { $this->_token = $_POST['token']; $this->_desc = $this->filter(($_POST['desc'])); $this->_fileName = $_FILES['file']['name']; $this->_fileTemp = $_FILES['file']['tmp_name']; $this->_fileSize = $_FILES['file']['size'] / 1024; $this->_fileType = $_FILES['file']['type']; $this->_folderName = $this->randString(8); $this->_folderPath = $this->_rootDir.$this->_folderName.'/'; $this->_imgName = $this->randString(6).'.'.$this->_fileExt; $this->_imgDest = $this->_folderPath.$this->_imgName; // uploads/76sd7/798234.jpg $this->_thumbDest = $this->_folderPath.$this->_thumbPrefix.$this->_imgName; // uploads/76sd7/thumb_798234.jpg } public function filter($var) { } public function isDescValid() { } public function lenghDesc() { } public function process() { try { if(!$this->isTokenValid()) throw new Exception('Invalid form submission'); if(!$this->isImageValid()) throw new Exception('Invalid image type and/or size'); if(!$this->lenghDesc()) throw new Exception('Max limit for description are 100 characters'); if(!$this->isDescValid()) throw new Exception('Your description contains invalid characters'); if(!$this->saveImage()) throw new Exception('Could not save image'); return true; } catch(Exception $e) { $this->_errors[] = $e->getMessage(); return false; } } public function saveImage() { try { if(!$this->createImageDir()) throw new Exception(); if(!$this->moveUploadedFile()) throw new CustomException(); if(!$this->createImageThumb()) throw new CustomException(); if(!$this->saveToDatabase()) throw new CustomException(); return true; } catch(Exception $e) {} catch(CustomException $e) { $this->removeImageDir(); } return false; } public function createImageDir() { { return true; } else return false; } public function removeImageDir() { } public function moveUploadedFile() { } public function isImageValid() { return (($this->_fileExt != "jpg" && $this->_fileExt != "jpeg" && $this->_fileExt != "gif") || ($this->_fileSize > 2048))? 0 : 1; } public function isTokenValid() { } public function saveToDatabase() { mysql_query("INSERT INTO store (filename,folder,para) VALUES ('{$this->_imgName}','{$this->_folderName}','{$this->_desc}')"); } public function createImageThumb() { if($this->_fileExt == "jpg") { //create new image from file $img = imagecreatefromjpeg($this->_imgDest); //get image size $width = imagesx($img); $height = imagesy($img); // calculate thumbnail size $new_width = $this->_thumbWidth; // create a new temporary image $tmp_img = imagecreatetruecolor($new_width,$new_height); // copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width,$new_height,$width,$height); // save thumbnail into a file imagejpeg($tmp_img, $this->_thumbDest) ; } else if($this->_fileExt == "gif") { $img = imagecreatefromgif($this->_imgDest); //get image size $width = imagesx($img); $height = imagesy($img); // calculate thumbnail size $new_width = $this->_thumbWidth; // create a new temporary image $tmp_img = imagecreatetruecolor($new_width,$new_height); // copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width,$new_height,$width,$height); // save thumbnail into a file imagegif($tmp_img, $this->_thumbDest); } } public function showErrors() { foreach($this->_errors as $key=>$value) } public function randString($length = 5) { $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; for($x=0; $x<$length; $x++) return $string; } } ?>
Dodawanie obrazków wymaga rejestracji i zalogowania co zajmuje góra 2 min (nie ma żadnych zwrotnych emaili z linkami aktywacyjnymi)
Będe wdzięczny za pomoc
Pozdro