Esempio n. 1
0
File: add.php Progetto: WanSpi/wcms
 public function init()
 {
     $this->view = false;
     $res = array();
     foreach ($_FILES as $file) {
         preg_match("/\\/(.+)/", $file["type"], $type);
         $url = $this->createPath() . "." . $type[1];
         move_uploaded_file($file["tmp_name"], $url);
         $image = new images();
         $image->url = $url;
         $image->name = $file["name"];
         $image->size = $file["size"];
         $image->save();
         $img = images::findFirst(array("where" => "url = '{$url}'"));
     }
     echo json_encode(array("id" => $img->id, "url" => $image->url), JSON_FORCE_OBJECT);
 }
Esempio n. 2
0
 public function executeSaveImages(sfWebRequest $request)
 {
     $data = $request->getPostParameter("stuff");
     //Sent from AJAX.
     if (!empty($data)) {
         $data = json_decode($data);
         //Decode from JSON to PHP array
         $color = $data->color;
         //eg, "red"
         $keywords = $data->keywords;
         //eg, "unicorns"
         $images = $data->images;
         // Array of URLs
         $keyword = new keywords();
         //MySQL INSERT.
         $keyword->setKeyword($keywords);
         $keyword->save();
         //Query executed
         $keyword_identifier = $keyword->identifier();
         $keyword_id = $keyword_identifier["id"];
         //$keyword->identifier()["id"]; not possible :(
         foreach ($images as $image_url) {
             $image = new images();
             //MySQL INSERT
             $image->setColor($color);
             //All images have the same $color and $keywords.
             $image->setUrl($image_url);
             $image->save();
             //Query executed
             $image_identifier = $image->identifier();
             $image_id = $image_identifier["id"];
             $image_keyword_relationship = new image_keyword_map();
             $image_keyword_relationship->setKeywordId($keyword_id);
             $image_keyword_relationship->setImageId($image_id);
             $image_keyword_relationship->save();
             //Query executed
         }
     }
 }
Esempio n. 3
0
 /**
 * Изменяет и сохраняет изображение
 */
 function saveImage($src, $dst, $param = null)
 {
     $img = new images($src, isset($param['w']) ? intval($param['w']) : null, isset($param['h']) ? intval($param['h']) : null, isset($param['fixed']) ? true : false, isset($param['ha']) ? $param['ha'] : 'center', isset($param['va']) ? $param['va'] : 'middle', isset($param['rgb']) ? $param['rgb'] : null, isset($param['alpha']) ? true : false, isset($param['max']) ? $param['max'] : 1024);
     if (isset($param['waterMark'])) {
         $water = new images($param['waterMark'], isset($param['waterW']) ? intval($param['waterW']) : null, isset($param['waterH']) ? intval($param['waterH']) : null, isset($param['waterFixed']) ? true : false, isset($param['waterHa']) ? $param['waterHa'] : 'center', isset($param['waterVa']) ? $param['waterVa'] : 'middle', isset($param['waterRGB']) ? $param['waterRGB'] : null, isset($param['waterAlpha']) ? true : false, isset($param['waterMax']) ? $param['waterMax'] : 1024);
         $img->addWatermark($water, isset($param['waterOffsetX']) ? $param['waterOffsetX'] : 0, isset($param['waterOffsetY']) ? $param['waterOffsetY'] : 0, isset($param['waterOpacity']) ? $param['waterOpacity'] : 100, isset($param['waterAlignH']) ? $param['waterAlignH'] : null, isset($param['waterAlignV']) ? $param['waterAlignV'] : null);
     }
     $res = $img->save($dst);
     if (isset($param['waterMark'])) {
         $water->__destruct();
     }
     $img->__destruct();
     return $res;
 }