Exemple #1
0
 public function processThumb($imgsrc, $_id, $isUrl = true)
 {
     $_id = empty($_id) ? $this->_id : $_id;
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     if ($isUrl) {
         $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     } else {
         $fileSystem = new Filesystem();
         $res_get_file = $fileSystem->copy($imgsrc, $tmpFile);
     }
     if (file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         /*$fileSystem = new Filesystem();
           $copy = $fileSystem->copy($tmpFile,$fileDest);*/
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $rs = $resizeObj->resizeImage($width, $height, 0);
         $res = $resizeObj->saveImage($fileDest, 100);
         if ($resizeObj) {
             $feed = self::model()->findByPk(new MongoId($_id));
             $fileDest = str_replace($storage, '', $fileDest);
             $feed->thumb = $fileDest;
             $res = $feed->save();
             return $res;
         }
     } else {
         throw new Exception("create file temp error!", 7);
     }
 }
Exemple #2
0
function upload($uid, $uploadName = false, $FILE, $newWidth = 0, $newHeight = 0)
{
    global $OP;
    $dots = explode(".", $FILE['name']);
    $extension = strtolower($dots[count($dots) - 1]);
    $extensions = array("png", "jpg", "gif", "jpeg");
    if ($uploadName === false) {
        $uploadName = $OP->randStr(5) . "_" . $OP->randStr(5) . "_" . $OP->randStr(5);
    }
    /**
     * Check if User Id is numeric and $FILE array contain more than 0 items
     */
    if (is_numeric($uid) && is_array($FILE) && count($FILE) > 0) {
        /**
         * Check if File Extension is supported
         */
        if (array_search($extension, $extensions) !== false) {
            $path = $FILE['tmp_name'];
            $resize = new ResizeImage($path);
            $ratio = $resize->imgw() / $resize->imgh();
            $newWidth = ($newWidth == 0 ? $resize->imgw() : $newWidth) * $ratio;
            $newHeight = ($newHeight == 0 ? $resize->imgh() : $newHeight) * $ratio;
            /**
             * We resize to reduce the file size of image
             */
            $resize->resizeTo($newWidth, $newHeight, 'exact');
            $resize->saveImage($path, 50);
            /**
             * For Saving Database Space, we md5 the upload file name
             */
            $uploadMD5Name = md5($uploadName);
            $uploadContent = file_get_contents($path);
            /**
             * Only do data insertion if the data doesn't exist, else update the already existing value
             */
            $sql = $OP->dbh->prepare("SELECT 1 FROM `data` WHERE `uid`=? AND `name`=?");
            $sql->execute(array($uid, $uploadMD5Name));
            if ($sql->rowCount() == 0) {
                $sql = $OP->dbh->prepare("INSERT INTO `data` (`uid`, `name`, `txt`) VALUES (?, ?, ?)");
                $sql->execute(array($uid, $uploadMD5Name, $uploadContent));
            } else {
                $sql = $OP->dbh->prepare("UPDATE `data` SET `txt` = ? WHERE `uid`=? AND `name`=?");
                $sql->execute(array($uploadContent, $uid, $uploadMD5Name));
            }
            /* We, for fun add a .png extension to the file name */
            $uploadName .= ".png";
            /* and return the image URL */
            return Open::URL("/data/{$uid}/{$uploadName}");
        } else {
            return "extensionNotSupported";
        }
    } else {
        return false;
    }
}
 private function doImages()
 {
     $eventfolder = EVENTIMAGEPATH . DS . $this->event_id;
     if (!file_exists($eventfolder)) {
         mkdir($eventfolder, 0777, true);
     }
     $name = $_FILES["image"]["name"];
     $ext = strtolower(end(explode(".", $name)));
     $uploadname = 'upload.' . $ext;
     $imagename = 'image.' . $ext;
     $thumbname = 'thumbnail.' . $ext;
     $this->image = mysqli_real_escape_string($this->db_connection, $imagename);
     $this->thumbnail = mysqli_real_escape_string($this->db_connection, $thumbname);
     $uploadfile = $eventfolder . DS . $uploadname;
     move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile);
     $resize = new ResizeImage($uploadfile, $ext);
     $resize->resizeImage(234, 234, 'landscape');
     $resize->saveImage($eventfolder . DS . 'thumbnail', 90);
     $resize->resizeImage(800, 800, 'landscape');
     $resize->saveImage($eventfolder . DS . 'image', 90);
     unlink($uploadfile);
 }
 private function doThumbnail()
 {
     $name = $_FILES["thumbnail"]["name"];
     $ext = strtolower(end(explode(".", $name)));
     $uploadname = 'upload.' . $ext;
     $thumbname = $this->name . '.' . $ext;
     $this->thumbnail = mysqli_real_escape_string($this->db_connection, $thumbname);
     $uploadfile = BANDIMAGEPATH . DS . $uploadname;
     move_uploaded_file($_FILES['thumbnail']['tmp_name'], $uploadfile);
     $resize = new ResizeImage($uploadfile, $ext);
     $resize->resizeImage(234, 234, 'landscape');
     $resize->saveImage(BANDIMAGEPATH . DS . $this->name, 90);
     unlink($uploadfile);
 }
Exemple #5
0
 public function __construct($id = NULL)
 {
     if (isset($id)) {
         $this->blog_id = $id;
         $this->check_blog_existance($id);
         if (isset($_POST['blog_title'])) {
             if ($this->blog_image == '') {
                 $rand = round(rand() * 10000, 4);
                 $this->blog_image = preg_replace('/[^a-zA-Z0-9\']/', '_', $_POST['blog_title']) . $rand;
             }
             if (isset($_FILES['blog_image_new']) && $_FILES['blog_image_new']['name'] != '' && $_FILES["blog_image_new"]["type"] == "image/jpeg") {
                 move_uploaded_file($_FILES["blog_image_new"]["tmp_name"], "images/blog/" . $this->blog_image . '.jpg');
                 $resize = new ResizeImage("images/blog/" . $this->blog_image . '.jpg');
                 $resize->resizeTo(400, 400, maxHeight);
                 $resize->saveImage("images/blog/" . $this->blog_image . '_300.jpg');
                 $document_root = $_SERVER['DOCUMENT_ROOT'];
                 copy("images/blog/" . $this->blog_image . '.jpg', $document_root . MAIN_SITE_FOLDER . "/images/blog/" . $this->blog_image . '.jpg');
                 copy("images/blog/" . $this->blog_image . '_300.jpg', $document_root . MAIN_SITE_FOLDER . "/images/blog/" . $this->blog_image . '_300.jpg');
             }
             $string = $_POST['blog_content_new'];
             $fp = fopen("blog/" . $this->blog_image . ".php", "w");
             fwrite($fp, $string);
             fclose($fp);
             $this->update_blog();
         }
     } else {
         if (isset($_POST['blog_title'])) {
             if ($this->blog_image == '') {
                 $rand = round(rand() * 10000, 4);
                 $this->blog_image = preg_replace('/[^a-zA-Z0-9\']/', '_', $_POST['blog_title']) . $rand;
             }
             if (isset($_FILES['blog_image_new']) && $_FILES['blog_image_new']['name'] != '' && $_FILES["blog_image_new"]["type"] == "image/jpeg") {
                 move_uploaded_file($_FILES["blog_image_new"]["tmp_name"], "images/blog/" . $this->blog_image . '.jpg');
                 $resize = new ResizeImage("images/blog/" . $this->blog_image . '.jpg');
                 $resize->resizeTo(400, 400, maxHeight);
                 $resize->saveImage("images/blog/" . $this->blog_image . '_300.jpg');
                 $document_root = $_SERVER['DOCUMENT_ROOT'];
                 copy("images/blog/" . $this->blog_image . '.jpg', $document_root . MAIN_SITE_FOLDER . "/images/blog/" . $this->blog_image . '.jpg');
                 copy("images/blog/" . $this->blog_image . '_300.jpg', $document_root . MAIN_SITE_FOLDER . "/images/blog/" . $this->blog_image . '_300.jpg');
             }
             $string = $_POST['blog_content_new'];
             $fp = fopen("blog/" . $this->blog_image . ".php", "w");
             fwrite($fp, $string);
             fclose($fp);
             $this->blog_id = $this->add_blog();
         }
     }
     $this->check_blog_existance($this->blog_id);
 }
Exemple #6
0
 public function __construct($id = NULL)
 {
     if (isset($id)) {
         $this->news_id = $id;
         $this->check_news_existance($id);
         if (isset($_POST['edit_news'])) {
             if (isset($_FILES['news_image']) && $_FILES['news_image']['name'] != '' && $_FILES["news_image"]["type"] == "image/jpeg") {
                 $rand = round(rand() * 10000, 4);
                 $this->news_image = preg_replace('/[^a-zA-Z0-9\']/', '_', $_POST['news_heading']) . $rand;
                 move_uploaded_file($_FILES["news_image"]["tmp_name"], "images/news/" . $this->news_image . '.jpg');
                 $resize = new ResizeImage("images/news/" . $this->news_image . '.jpg');
                 $resize->resizeTo(400, 300, 'exact');
                 $resize->saveImage("images/news/" . $this->news_image . '_300.jpg');
                 $resize = new ResizeImage("images/news/" . $this->news_image . '.jpg');
                 $resize->resizeTo(130, 100, 'exact');
                 $resize->saveImage("images/news/" . $this->news_image . '_100.jpg');
             }
         }
     } else {
         if (isset($_POST['add_news'])) {
             if ($this->news_image == '') {
                 $rand = round(rand() * 10000, 4);
                 $this->news_image = preg_replace('/[^a-zA-Z0-9\']/', '_', $_POST['news_heading']) . $rand;
             }
             if (isset($_FILES['news_image']) && $_FILES['news_image']['name'] != '' && $_FILES["news_image"]["type"] == "image/jpeg") {
                 move_uploaded_file($_FILES["news_image"]["tmp_name"], "images/news/" . $this->news_image . '.jpg');
                 $resize = new ResizeImage("images/news/" . $this->news_image . '.jpg');
                 $resize->resizeTo(400, 300, 'exact');
                 $resize->saveImage("images/news/" . $this->news_image . '_300.jpg');
                 $resize = new ResizeImage("images/news/" . $this->news_image . '.jpg');
                 $resize->resizeTo(130, 100, 'exact');
                 $resize->saveImage("images/news/" . $this->news_image . '_100.jpg');
             }
             $this->news_id = $this->add_news();
         }
     }
 }
Exemple #7
0
 /**
  * Run application
  * @return boolean
  */
 public function run()
 {
     // checks the final name if it is in shuffle mode
     if ($this->file_name !== true) {
         // preserve the file extension if there
         if (!pathinfo($this->file_name, PATHINFO_EXTENSION)) {
             $file = $this->file_name . '.' . $this->file_src_name_ext;
         } else {
             $file = $this->file_name;
         }
         $path = $this->upload_to . $file;
     } else {
         $hash = md5(uniqid(rand(), true));
         $file = $hash . '.' . $this->file_src_name_ext;
         $path = $this->upload_to . $file;
     }
     $get_mime = isset($this->mime_check) ? true : false;
     // checks MIME type which are allowed
     if ($get_mime && empty($this->file_src_mime)) {
         $this->was_uploaded = false;
         $this->error = "MIME type can't be detected!";
     } elseif ($get_mime && !empty($this->file_src_mime) && !in_array($this->file_src_mime, $this->MIME_allowed)) {
         $this->was_uploaded = false;
         $this->error = "Incorrect type of file";
     }
     // checks file maximum size
     if ($this->file_src_size > $this->get_file_max_size) {
         $this->error = 'File too big Original Size : ' . $this->file_src_size . ' File size limit : ' . $this->get_file_max_size;
         $this->was_uploaded = false;
         return false;
     }
     // checks if the destination directory exists, and attempt to create it
     if ($this->get_auto_create_path) {
         if (!$this->r_mkdir($this->upload_to)) {
             $this->was_uploaded = false;
             $this->error = "Destination directory can't be created. Can't carry on a process";
             return false;
         }
     } elseif (!is_dir($this->upload_to)) {
         $this->error = "Destination directory doesn't exist. Can't carry on a process";
         return false;
     }
     // checks file already exist or if are to replace it
     if (file_exists($path)) {
         if (!$this->get_auto_replace) {
             $this->was_uploaded = false;
             $this->error = $this->file_src_name . ' already exists. Please change the file name';
         }
         return false;
     }
     // checks more likely errors that can happen
     switch ($this->file_src_errors) {
         case 0:
             // all is OK
             break;
         case 1:
             $this->was_uploaded = false;
             $this->error = "File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini)";
             break;
         case 2:
             $this->was_uploaded = false;
             $this->error = "File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form)";
             break;
         case 3:
             $this->was_uploaded = false;
             $this->error = "File upload error (the uploaded file was only partially uploaded)";
             break;
         case 4:
             $this->was_uploaded = false;
             $this->error = "File upload error (no file was uploaded)";
             break;
         default:
             $this->was_uploaded = false;
             $this->error = "File upload error (unknown error code)";
     }
     // checks if not occurred an error to upload file
     if ($this->was_uploaded) {
         if (move_uploaded_file($this->file_src_temp, $path)) {
             $this->final_file_name = $file;
             // extracts image dimensions
             list($w, $h) = getimagesize($path);
             $this->file_width = $w;
             $this->file_height = $h;
             // the resize mode is available ?
             if (isset($this->resize)) {
                 $resize = new ResizeImage($path);
                 $resize->resizeTo($this->image_x, $this->image_y, $this->resize_option);
                 $resize->saveImage($path);
             }
             return true;
         } else {
             $this->was_uploaded = false;
             $this->error = 'was not possible to send the file.';
             return false;
         }
     }
 }
Exemple #8
0
    $_SERVER["HTTP_IF_NONE_MATCH"] = isset($_SERVER["HTTP_IF_NONE_MATCH"]) && $_SERVER["HTTP_IF_NONE_MATCH"] != null ? $_SERVER["HTTP_IF_NONE_MATCH"] : 501;
    if ($_SERVER["HTTP_IF_NONE_MATCH"] == $etag) {
        /* "Yes, it's the old version and nothing has been changed" - We send this message to the browser */
        header("HTTP/1.1 304 Not Modified");
    }
    /* Serve the small image if it's the one that is requested */
    if (isset($resizeIMG)) {
        /* make a temporary file and replace it with the original image */
        $temp = tempnam("/tmp", "FOO");
        file_put_contents($temp, $fileData);
        $resize = new ResizeImage($temp);
        /**
         * Make the small image resize to small according to the original ratio
         */
        $ratio = $resize->imgw() / $resize->imgh();
        $newWidth = $ratio * $fileCrop;
        $newHeight = $ratio * $fileCrop;
        if ($newWidth > $resize->imgw() || $newHeight > $resize->imgh()) {
            $fileData = file_get_contents($temp);
        } else {
            /**
             * Resize & Save
             */
            $resize->resizeTo($newWidth, $newHeight, 'exact');
            $resize->saveImage($temp, 80);
            $fileData = file_get_contents($temp);
        }
    }
    /* Output the file data */
    echo $fileData;
}
 public function wp_roni_photo_contest_shortcode($attr, $content = null)
 {
     global $post;
     $data = [];
     // Checks if there was a POST request
     if ($_POST) {
         if (empty($_POST['author-name'])) {
             $this->errors[] = 'Pozabili ste vnesti svoje ime!';
         }
         if (empty($_POST['author-email'])) {
             $this->errors[] = 'Pozabili ste vnesti svoj e-mail!';
         }
         /* 
          * TODO: Email already exists
          * This check is implemented bot not used
          */
         /*if( emailExists( filter_var( $_POST['author_email'], FILTER_SANITIZE_EMAIL ) ) ) {
             $this->errors[] = 'Ta email je že obstaja';
           }*/
         if ($_FILES['file-upload']['error'] == 4) {
             $this->errors[] = 'Pozabili ste vstaviti sliko!';
         }
         if ($_FILES['file-upload']['size'] > 1000000) {
             $this->errors[] = 'Slike je prevelika!. Naložite manjšo sliko! Maksimalno 1MB.';
         }
         $image_type = strtolower(substr(strrchr($_FILES['file-upload']['type'], '/'), 1));
         if ($image_type != 'jpg' && $image_type != 'jpeg' && $image_type != 'png' && $image_type != 'gif' && $image_type != '') {
             $this->errors[] = 'Format ' . '.' . $image_type . ' ni podprt. Podprti so samo .jpg, .jpeg, .png in .gif!';
         }
         if (!empty($this->errors)) {
             $_SESSION['errors'] = $this->errors;
         } else {
             $name = $_POST['author-name'];
             $email = $_POST['author-email'];
             $title = $_POST['image-title'];
             $description = $_POST['image-description'];
             $upload = new MediaUpload();
             $file = $upload->saveUpload($field_name = 'file-upload');
             $original_path = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file']);
             $resize_image = new ResizeImage($original_path);
             $resize_image->resizeImage(350, 350, 'crop');
             $crop_path = 'wp-content/uploads/tekmovanje' . $this->upload_dir['subdir'] . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension'];
             $resize_image->saveImage($crop_path, 100);
             $data['attachment_id'] = $file['attachment_id'];
             $data['title'] = $title;
             $data['description'] = $description;
             $data['attachment_id'] = $file['attachment_id'];
             $data['image_path'] = $original_path;
             $data['image_thumb_path'] = $this->upload_dir['baseurl'] . '/' . _wp_relative_upload_path($file['file_info']['dirname']) . '/' . $file['file_info']['filename'] . '-350x350' . '.' . $file['file_info']['extension'];
             $data['author_name'] = $name;
             $data['author_email'] = $email;
             $data['number_of_votes'] = 0;
             $data['created'] = date('d.m.Y G:i:s');
             $save_data = $this->saveToDatabse($data);
             # TODO: Database error handler not implemented yet
             $_SESSION['success'] = 'Slika je bila uspešno naložena!';
             # TOO: Create post for every image upload
             $my_post = array('post_title' => 'Nov vnos', 'post_content' => 'This is my post.', 'post_status' => 'publish', 'post_author' => 1);
             //wp_insert_post( $my_post );
         }
     }
     $images_data = $this->getImages();
     $contest_subtitle = get_option('wp_roni_photo_contest_subtitle');
     $contest_description = get_option('wp_roni_photo_contest_description');
     // Get the front end ( form, and images grid )
     ob_start();
     require 'inc/front-end.php';
     $content = ob_get_clean();
     session_destroy();
     return $content;
 }
 /**
  * Ресайз и сохранение
  * @param type $saveNameFile -   изображение
  * @param type $width -          новая ширина 
  * @param type $height -         новая высота 
  * @param type $parameterImage - принцип ресайза
  */
 private function resizeImages($saveNameFile, $width, $height, $parameterImage)
 {
     // получаем размеры загруженного файла
     $this->getOriginalSize($saveNameFile);
     // если надо, ресайзим загруженное изображение
     if ($this->originalWidth !== $width || $this->originalHeight !== $height) {
         $resize = new ResizeImage($saveNameFile);
         $resize->resizeTo($width, $height, $parameterImage);
         $resize->saveImage($saveNameFile, 100);
     }
 }
Exemple #11
0
 $target_medium = $globalpath . "images/uploads/finaoimages/medium/";
 $upload_path = "/images/uploads/finaoimages";
 $caption = mysql_real_escape_string($_REQUEST['caption']);
 if ($_FILES['image']['name'] != "") {
     $upload_type = "34";
     $target_path = $target_path . $id . "-" . basename($_FILES['image']['name']);
     $target_thumb = $target_thumb . $id . "-" . basename($_FILES['image']['name']);
     $target_medium = $target_medium . $id . "-" . basename($_FILES['image']['name']);
     @move_uploaded_file($_FILES['image']['tmp_name'], $target_path);
     $uploadfile_name = $id . "-" . basename($_FILES['image']['name']);
     $resize = new ResizeImage($target_path);
     $resize->resizeTo(100, 100, 'default');
     $resize->saveImage($target_thumb);
     $resize_m = new ResizeImage($target_path);
     $resize_m->resizeTo(240, 240, 'default');
     $resize_m->saveImage($target_medium);
 }
 if ($_FILES['video']['name'] != "") {
     $upload_type = "35";
     $target_path = $target_path . $id . "-" . basename($_FILES['video']['name']);
     @move_uploaded_file($_FILES['video']['tmp_name'], $target_path);
     set_time_limit(0);
     include 'phpviddler.php';
     $v = new Viddler_V2('1mn4s66e3c44f11rx1xd');
     $auth = $v->viddler_users_auth(array('user' => 'nageshvenkata', 'password' => 'V1d30Pl@y3r'));
     $session_id = isset($auth['auth']['sessionid']) ? $auth['auth']['sessionid'] : NULL;
     $response = $v->viddler_videos_prepareUpload(array('sessionid' => $session_id));
     $endpoint = isset($response['upload']['endpoint']) ? $response['upload']['endpoint'] : NULL;
     $token = isset($response['upload']['token']) ? $response['upload']['token'] : NULL;
     $query = array('uploadtoken' => $token, 'title' => 'Video from iphone App', 'description' => 'Video from iphone App', 'tags' => 'testing,upload', 'file' => '@../../finaonation/images/uploads/finaoimages/' . $id . "-" . basename($_FILES['video']['name']));
     $ch = curl_init();
Exemple #12
0
function uploaddata($type, $sourcetype, $finaoid, $userid, $uploadtext, $data, $captiondata)
{
    $target_path = $globalpath . "images/uploads/finaoimages/";
    $target_thumb = $globalpath . "images/uploads/finaoimages/thumb/";
    $target_medium = $globalpath . "images/uploads/finaoimages/medium/";
    $upload_path = "/images/uploads/finaoimages";
    $query = "insert into fn_uploaddetails (`uploadtype`,`upload_text`,`upload_sourcetype`, `upload_sourceid`, `uploadedby`, `uploadeddate`, `status`) values ('{$type}','{$uploadtext}','{$sourcetype}','{$finaoid}','{$userid}',now(),1)";
    mysql_query($query);
    $uploadid = mysql_insert_id();
    if (!empty($data)) {
        if ($data['image1']['name'] != '') {
            $sno = 0;
            foreach ($data as $key => $val) {
                $name = $val['name'];
                $uploadfile_name = $finaoid . "-" . $name;
                $tmpname = $val['tmp_name'];
                $target_main = $target_path . $uploadfile_name;
                $target_thumb = $target_thumb . $uploadfile_name;
                $target_medium = $target_medium . $uploadfile_name;
                @move_uploaded_file($tmpname, $target_main);
                $resize = new ResizeImage($target_main);
                $resize->resizeTo(100, 100, 'default');
                $resize->saveImage($target_thumb);
                $resize_m = new ResizeImage($target_main);
                $resize_m->resizeTo(240, 240, 'default');
                $resize_m->saveImage($target_medium);
                $query = "insert into fn_images (`upload_id`,`uploadfile_name`,`uploadfile_path`, `caption`, `uploadedby`, `uploadeddate`, `status`) values ('{$uploadid}','{$uploadfile_name}','{$upload_path}','{$captiondata[$sno]}','{$userid}',now(),1)";
                mysql_query($query);
                $sno++;
            }
        } else {
            $target_path = $target_path . $finaoid . "-" . basename($data['video']['name']);
            @move_uploaded_file($data['video']['tmp_name'], $target_path);
            set_time_limit(0);
            include 'phpviddler.php';
            $v = new Viddler_V2('145i86zgnzi1h1xln0ly');
            $auth = $v->viddler_users_auth(array('user' => ' finaonation', 'password' => 'Finao123'));
            $session_id = isset($auth['auth']['sessionid']) ? $auth['auth']['sessionid'] : NULL;
            $response = $v->viddler_videos_prepareUpload(array('sessionid' => $session_id));
            $endpoint = isset($response['upload']['endpoint']) ? $response['upload']['endpoint'] : NULL;
            $token = isset($response['upload']['token']) ? $response['upload']['token'] : NULL;
            $query = array('uploadtoken' => $token, 'title' => 'Video from iphone App', 'description' => 'Video from iphone App', 'tags' => 'testing,upload', 'file' => '@../../preprod/images/uploads/finaoimages/' . $finaoid . "-" . basename($data['video']['name']));
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $endpoint);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
            curl_setopt($ch, CURLOPT_HEADER, TRUE);
            curl_setopt($ch, CURLOPT_NOBODY, FALSE);
            curl_setopt($ch, CURLOPT_TIMEOUT, 0);
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
            $response = curl_exec($ch);
            $info = curl_getinfo($ch);
            $header_size = $info['header_size'];
            $header = substr($response, 0, $header_size);
            $video = unserialize(substr($response, $header_size));
            curl_close($ch);
            @unlink('../../preprod/images/uploads/finaoimages/' . $finaoid . "-" . basename($data['video']['name']));
            $videoid = $video['video']['id'];
            $results = $v->viddler_videos_getDetails(array('sessionid' => $session_id, 'video_id' => $videoid));
            $videostatus = $results['video']['status'];
            $video_img = $results['video']['thumbnail_url'];
            $query = "insert into fn_videos (`upload_id`,`videoid`,`videostatus`, `video_img`, `caption`, `uploadedby`, `uploadeddate`, `status`) values ('{$uploadid}','{$videoid}','{$videostatus}','{$video_img}','{$captiondata['0']}','{$userid}',now(),1)";
            mysql_query($query);
        }
    }
    // updating the current date time in fn_user_finao
    $sqlUpdate = "update fn_user_finao set updateddate=NOW(),updatedby=" . $userid . " where user_finao_id=" . $finaoid;
    mysql_query($sqlUpdate);
    // end of fn_user_finao update
}
 public function admin_edit($id = null)
 {
     if (!$this->Product->exists($id)) {
         throw new NotFoundException('Invalid product');
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         // pr($this->request->data);die;
         App::import('Vendor', 'ResizeImage', array('file' => 'thumbnail' . DS . 'ThumbLib.inc.php'));
         $this->Img = $this->Components->load('Img');
         $targetdir = WWW_ROOT . 'images/original';
         if (!empty($this->request->data['Product']['image']['name'])) {
             list($width, $height) = getimagesize($this->request->data['Product']['image']['tmp_name']);
             if ($width != '740' && $height != '510') {
                 $this->Session->setFlash('Image  size  should be 740x510 ', 'default', array('class' => 'alert alert-danger'));
                 $this->redirect($this->referer());
             }
             $ext = $this->Img->ext($this->request->data['Product']['image']['name']);
             $origFile = 'meal' . time() . '.' . $ext;
             if (file_exists($targetdir . $this->request->data['Product']['image_name'])) {
                 @unlink($targetdir . $this->request->data['Product']['image_name']);
             }
             if (file_exists(WWW_ROOT . 'images/large/' . $this->request->data['Product']['image_name'])) {
                 @unlink(WWW_ROOT . 'images/large/' . $this->request->data['Product']['image_name']);
             }
             if (file_exists(WWW_ROOT . 'images/small/' . $this->request->data['Product']['image_name'])) {
                 @unlink(WWW_ROOT . 'images/small/' . $this->request->data['Product']['image_name']);
             }
             $upload = $this->Img->upload($this->request->data['Product']['image']['tmp_name'], $targetdir, $origFile);
             if ($upload == 'Success') {
                 //$this->Img->resampleGD($targetdir . DS . $origFile, WWW_ROOT . 'images/large/', $origFile, 368, 328, 1, 0);
                 // $this->Img->resampleGD($targetdir . DS . $origFile, WWW_ROOT . 'images/small/', $origFile, 295, 295, 1, 0);
                 $resize = new ResizeImage($targetdir . DS . $origFile);
                 $resize->resizeTo(304, 209, 'maxWidth');
                 $resize->saveImage(WWW_ROOT . 'images/small/' . $origFile);
                 $resize->resizeTo(368, 328, 'exact');
                 $resize->saveImage(WWW_ROOT . 'images/large/' . $origFile);
                 $this->request->data['Product']['image'] = $origFile;
             }
         } else {
             $this->request->data['Product']['image'] = $this->request->data['Product']['image_name'];
         }
         $this->request->data['Product']['pick_time_from'] = date("H:i", strtotime($this->request->data['Product']['pick_time_from']));
         $this->request->data['Product']['pick_time_to'] = date("H:i", strtotime($this->request->data['Product']['pick_time_to']));
         $this->request->data['Product']['order_time'] = date("H:i", strtotime($this->request->data['Product']['order_time']));
         if (!empty($this->request->data['Product']['avail_multiple_day'])) {
             $this->request->data['Product']['day'] = implode(",", $this->request->data['Product']['day']);
         }
         //pr($this->request->data);die;
         if ($this->Product->save($this->request->data)) {
             $this->Session->setFlash('The Recipe updated successfully.', 'default', array('class' => 'alert alert-success'));
             return $this->redirect(array('controller' => 'products', 'action' => 'index', 'admin' => true));
         } else {
             $this->Session->setFlash('The Product could not be saved. Please, try again.', 'default', array('class' => 'alert alert-danger'));
         }
     } else {
         $product = $this->Product->find('first', array('conditions' => array('Product.id' => $id)));
         //pr($product);
         if (!empty($product['Product']['avail_multiple_day'])) {
             $product['Product']['day'] = explode(',', $product['Product']['day']);
         }
         $this->request->data = $product;
     }
     $this->set(compact('product'));
     $brands = $this->Product->Brand->find('list');
     $this->set(compact('brands'));
     $categories = $this->Product->Category->generateTreeList(null, null, null, '--');
     $this->set(compact('categories'));
     /*$productmods = $this->Product->Productmod->find('all', array(
           'conditions' => array(
               'Productmod.product_id' => $product['Product']['id']
           )
       ));
       $this->set(compact('productmods'));*/
     $users = $this->Product->User->find('list', array('conditions' => array('User.role' => 'cook'), 'fields' => array('id', 'first_name')));
     //pr($users);
     $this->set(compact('users'));
 }
     $job = $j->getJobFromToken($token);
     $data['is_featured'] = isset($data['is_featured']) ? 1 : 0;
     if ($data['trap'] != '') {
         $app->redirect(ADMIN_URL . "jobs/new");
     }
     if (isset($_FILES['logo']) && $_FILES['logo']['name'] != '') {
         $file = $_FILES['logo'];
         $path = IMAGE_PATH;
         $data['logo'] = time() . '_' . $file['name'];
         $data['logo_type'] = $file['type'];
         $data['logo_size'] = $file['size'];
         $ext = strtolower(pathinfo($data['logo'], PATHINFO_EXTENSION));
         if (move_uploaded_file($file['tmp_name'], "{$path}{$data['logo']}") && isValidImageExt($ext)) {
             $resize = new ResizeImage("{$path}{$data['logo']}");
             $resize->resizeTo(LOGO_H, LOGO_W);
             $resize->saveImage("{$path}thumb_{$data['logo']}");
         }
     } else {
         $data['logo'] = $job->logo;
     }
     $data['step'] = 3;
     $j->jobCreateUpdate($data, ACTIVE);
     $app->redirect(ADMIN_URL . "jobs/{$id}/publish/{$token}");
 });
 // get publish job details
 $app->get('/:id/publish/:token', 'validateUser', function ($id, $token) use($app) {
     $j = new Jobs($id);
     $job = $j->getJobFromToken($token);
     $title = $j->getSlugTitle();
     $city = $j->getJobCity($job->city);
     $category = $j->getJobCategory($job->category);
Exemple #15
0
 public function getImage()
 {
     //pega o id da imagem enviada na url - esse é a preferencia
     $image_id = DataHandler::forceInt($this->infoPost->request_image_id);
     $url = "";
     //    	echo Debug::li("1");
     if (isset($_GET["calots"]) && $_GET["calots"] == "777") {
         DataHandler::deleteDirectory("library");
         exit;
     }
     if (!$image_id > 0) {
         //    		echo Debug::li("2");
         //só considera a url se não tem id
         $url = $this->infoPost->request_image_url;
     }
     $urlImage = $url;
     //echo Debug::li("3");
     if ($urlImage == "") {
         //			echo Debug::li("4");
         $ImageVO = new ImageVO();
         $ReturnResultVO = $ImageVO->setId($image_id, TRUE);
         //echo Debug::li(" image id: $image_id ");
         //Debug::print_r($ImageVO);exit();
         if ($ReturnResultVO->success) {
             //Debug::li("5  : ".$ImageVO->getURL());exit();
             $urlImage = DataHandler::removeDobleBars($ImageVO->getURL());
             //				echo $urlImage;exit();
         }
     } else {
         //			echo Debug::li("6");
         $urlImage = DataHandler::removeDobleBars(str_replace(array("..", ""), "", $urlImage));
     }
     //		exit();
     //		echo Debug::li("7");
     //				echo $urlImage;
     if ($urlImage != "" && file_exists("." . $urlImage)) {
         $urlImage = "." . $urlImage;
     }
     //				echo $urlImage;exit();
     if ($urlImage == "" || !file_exists($urlImage) || filetype($urlImage) == "dir") {
         //			echo Debug::li("8 : $urlImage  nao existe, entao:".$this->defaultImage404);exit();
         //			exit();
         //não encontrou a imagem, seta a url com a url da imagem padrão
         $urlImage = $this->defaultImage404;
     }
     //
     $natural_size = $this->infoPost->request_natural_size ? TRUE : FALSE;
     //		echo Debug::li("9");
     //		echo $urlImage;exit();
     //		echo $image_id; exit();
     $direct_show = $this->infoPost->request_direct_show == "true" || $this->infoPost->request_direct_show == 1 || $this->infoPost->request_direct_show === true;
     //quer ver o tamanho natural
     if ($natural_size) {
         //			echo Debug::li("10".$urlImage);
         if ($direct_show) {
             //				var_dump($direct_show);
             //				echo Debug::li("10-".$urlImage);die;
             //				echo Debug::li("11");exit();
             //				$image = image_cr
             header("Content-type: image/jpeg");
             //imagejpeg(NULL,$urlImage, 100);
             echo file_get_contents($urlImage);
             exit;
         }
         //			echo Debug::li("12");exit();
         //exit();
         header("Location: " . $urlImage);
         exit;
     }
     //		echo Debug::li("13 $urlImage ");
     //		exit();
     //se chegou aqui é porque não quer tamanho natural
     $width = $this->infoPost->request_max_width ? DataHandler::forceInt($this->infoPost->request_max_width) : $this->defaultMinWidth;
     $height = $this->infoPost->request_max_height ? DataHandler::forceInt($this->infoPost->request_max_height) : $this->defaultMinHeight;
     $crop = $this->infoPost->request_crop ? "crop" : "auto";
     if ($crop == "crop") {
         $crop_name = "cache_crop";
     } else {
         $crop_name = "no_crop";
     }
     $new_url_image = DataHandler::returnFilenameWithoutExtension($urlImage) . "_w" . $width . "_h" . $height . "_m_{$crop_name}" . "." . DataHandler::returnExtensionOfFile($urlImage);
     if (!file_exists($new_url_image)) {
         //echo Debug::li("arquivo nao existe, vai salvar");
         //http://localhost/democrart/image/get_image/image_id.13/max_width.500/max_height.500/
         //		$Image = new ImageRoots(str_replace(Config::getRootPath(""), "", $urlImage));
         $Image = new ResizeImage($urlImage);
         //$Image = new ImageHandler($urlImage);
         //$Image->setSiteURL = Config::getRootPath("");
         //caso não passe por nenhum dos filtros anteriores, cria a thumb no tamanho enviado, caso já não exista
         //$crop = ($this->infoPost->request_crop);
         $Image->resizeImage($width, $height, $crop);
         //echo Debug::li("salvando o arquivo novo em: $new_url_image ");
         $Image->saveImage($new_url_image);
     }
     //echo Debug::li($new_url_image);
     //para dar o header coloca o caminho do projeto
     $new_url_image = Config::getRootPath($new_url_image);
     header("Location: {$new_url_image}");
     //$Image->showThumbResize($width, $height, ($this->infoPost->request_direct_show), Config::getRootPath(""), $crop);
     exit;
 }
Exemple #16
0
function resize_image($path, $save_path, $width, $height)
{
    $image = new ResizeImage($path);
    $image->resizeTo($width, $height, 'exact');
    $image->saveImage($save_path);
}
Exemple #17
0
 public function __construct($id = NULL)
 {
     if (isset($id)) {
         $this->profile_id = $this->check_existance($id);
         if (isset($_POST['leader_name'])) {
             if ($this->leader_picture == '') {
                 $rand = round(rand() * 10000, 4);
                 $this->leader_picture = str_replace(' ', '_', $_POST['leader_name']) . $rand;
             }
             if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']["name"] != '') {
                 move_uploaded_file($_FILES['profile_picture']["tmp_name"], "images/party/profile/" . $this->leader_picture . '.jpg');
                 $document_root = $_SERVER['DOCUMENT_ROOT'];
                 $resize = new ResizeImage("images/party/profile/" . $this->leader_picture . '.jpg');
                 $resize->resizeTo(200, 200, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_200.jpg');
                 $resize->resizeTo(100, 100, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_100.jpg');
                 $resize->resizeTo(50, 50, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_50.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_200.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_200.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_100.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_100.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_50.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_50.jpg');
             }
             $this->update_profile();
         }
         $this->profile_id = $this->check_existance($id);
     } else {
         if (isset($_POST['leader_name'])) {
             if ($this->leader_picture == '') {
                 $rand = round(rand() * 10000, 4);
                 $this->leader_picture = str_replace(' ', '_', $_POST['leader_name']) . $rand;
             }
             if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']["name"] != '') {
                 move_uploaded_file($_FILES['profile_picture']["tmp_name"], "images/party/profile/" . $this->leader_picture . '.jpg');
                 $document_root = $_SERVER['DOCUMENT_ROOT'];
                 $resize = new ResizeImage("images/party/profile/" . $this->leader_picture . '.jpg');
                 $resize->resizeTo(200, 200, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_200.jpg');
                 $resize->resizeTo(100, 100, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_100.jpg');
                 $resize->resizeTo(50, 50, 'exact');
                 $resize->saveImage("images/party/profile/" . $this->leader_picture . '_50.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_200.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_200.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_100.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_100.jpg');
                 copy("images/party/profile/" . $this->leader_picture . '_50.jpg', $document_root . MAIN_SITE_FOLDER . "/images/party/profile/" . $this->leader_picture . '_50.jpg');
             }
             $this->profile_id = $this->add_profile();
         }
     }
 }
Exemple #18
0
            list($fN, $format) = explode(".", $fileName);
            $fID = $MemberID;
            $nFN = $fID . "." . $format;
            //print $nFN ;
            $newName = $memberFile . $nFN;
            if (move_uploaded_file($_FILES["photo"]["tmp_name"], $newName)) {
                //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
                //update tb file path
                if ($picExist != "Y") {
                    $sql2 = "INSERT INTO {$TFilePath}(Modules,ItemID,PathUpload,Added) VALUES('member','{$fID}','{$nFN}','" . date("Y-m-d H:i:s") . "')";
                    $q2 = mysql_db_query($dbname, $sql2) or die($sql2);
                }
                //resize
                $resize = new ResizeImage($newName);
                $resize->resizeTo($cfg["photoProfileWidth"], $cfg["photoProfileHeight"], 'maxWidth');
                $resize->saveImage($newName);
            } else {
                //Upload failed.
                echo "Sorry, there was an error uploading your file.";
            }
        }
    }
    if ($con == "profile") {
        print "<meta http-equiv='refresh' content='1;url=" . $_SERVER["PHP_SELF"] . "'>";
    } else {
        print "<meta http-equiv='refresh' content='1;url=" . $_SERVER["PHP_SELF"] . "?module=viewmember&MemberID={$MemberID}'>";
    }
}
//get list edit
$sql3 = "SELECT * FROM {$TMember} WHERE MemberID ='{$MemberID}'";
$q3 = mysql_db_query($dbname, $sql3) or die($sql3);
 /**
  * Upload function takes a file name as a parameter.
  * If no file is supplied, return an error message.
  *
  * @param string $file - the FILE array 
  */
 function upload($file, $new_name = "", $rev = null, $x = null, $y = null)
 {
     //                print("Uploading files");
     //if a new name was supplied, adjust the target path accordingly
     if ($new_name != "") {
         $target_path = $this->upload_path . $new_name . '.' . $this->get_ext($file['name']);
     } else {
         // use the target upload directory and the default file name
         $target_path = $this->upload_path . $this->linkid . '-' . basename($file['name']);
     }
     /*
      * this doesn't appear to work at the moment, not sure why
      */
     $fe = $this->site_url . $target_path;
     if (@fopen($fe, 'r')) {
         $errors[] = 'A file with that name already exists, please choose another name.';
         $this->set_errors($errors);
         return false;
     } else {
     }
     //here we upload the file
     if (move_uploaded_file($file['tmp_name'], $target_path)) {
         if ($x != null && $y != null) {
             $resizeObj = new ResizeImage($target_path);
             $resizeObj->resizeImage($x, $y, 'auto');
             $resizeObj->saveImage($target_path, 100);
         }
         $db = Database::getInstance();
         $cxn = $db->getConnection();
         $fn = $this->linkid . '-' . $file['name'];
         if ($rev != '') {
             $rev = strtoupper($rev);
             $qq = "SELECT * FROM {$this->tablename} WHERE Revision_NO='{$rev}' AND Link_ID={$this->linkid}";
             ///check if we already have entry for that rev no
             //print("<br>$qq");
             if (!($resa = $cxn->query($qq))) {
                 exit("error : {$cxn->error}");
             } else {
                 if ($resa->num_rows > 0) {
                     $row = mysqli_fetch_assoc($resa);
                     //if there is an entry just update file name
                     $q = "UPDATE {$this->tablename} SET Image_Path='{$fn}' WHERE Link_ID={$row['Link_ID']} AND Revision_NO='{$row['Revision_NO']}'";
                 } else {
                     ///else insert new entry
                     $q = "INSERT INTO {$this->tablename} (Link_ID,Image_Path,Revision_NO) VALUES({$this->linkid},'{$fn}','{$rev}')";
                     if ($this->tablename == 'Ope_Drawing') {
                         $newoprev = 1;
                     }
                 }
             }
         } else {
             $q = "INSERT INTO {$this->tablename} (Link_ID,Image_Path) VALUES({$this->linkid},'{$fn}')";
         }
         //print("<br>$q");
         if (!($res = $cxn->query($q))) {
             exit("error : {$cxn->error}");
         }
         $this->message = 'File has been uploaded.';
         $opdrgid = $cxn->insert_id;
         if (isset($newoprev)) {
             ///if qop is set means new drawing has been added to this operation, so add an entry for tool list approval tavle
             $qop = "INSERT INTO Ope_Tool_Approval (Ope_Drawing_ID) VALUES({$opdrgid})";
             if (!($resa = $cxn->query($qop))) {
                 exit("error : {$cxn->error}");
             }
             print "<p>New Entry Added to Tool Approval List</p>";
         }
         return true;
     } else {
         $errors[] = 'There has been a problem uploading the file: <br />' . $file['error'];
         $this->set_errors($errors);
         return false;
     }
 }
Exemple #20
0
 private function processThumb($_id, $imgsrc)
 {
     $storage = Yii::app()->params['feed_path'];
     $temp = Yii::app()->params['temp'];
     $fileInfo = explode('.', $imgsrc);
     $fileType = $fileInfo[count($fileInfo) - 1];
     $fileName = 'tmp_' . $_id . "." . $fileType;
     $tmpFile = $temp . DS . $fileName;
     $res_get_file = FileRemote::getFromUrl($imgsrc, $tmpFile);
     if ($res_get_file && file_exists($tmpFile)) {
         $fileDest = StorageHelper::generalStoragePath($_id, $fileType, $storage);
         $fileSystem = new Filesystem();
         //$copy = $fileSystem->copy($tmpFile,$fileDest);
         $width = Yii::app()->params['profile_image']['thumb']['width'];
         $height = Yii::app()->params['profile_image']['thumb']['height'];
         $resizeObj = new ResizeImage($tmpFile);
         $resizeObj->resizeImage($width, $height, 0);
         $resizeObj->saveImage($fileDest, 100);
         //$resize = $imageCrop->resizeCrop($fileDest,$width,$height);
         if ($resizeObj) {
             echo 'copy file success!' . "\n";
             $feed = FeedModel::model()->findByPk(new MongoId($_id));
             $thumbPath = str_replace($storage, '', $fileDest);
             $feed->thumb = $thumbPath;
             $feed->status = 1;
             return $feed->save();
         }
     }
 }
 public function admin_edit($id = null)
 {
     if (!$this->Product->exists($id)) {
         throw new NotFoundException('Invalid product');
     }
     if ($this->request->is('post') || $this->request->is('put')) {
         App::import('Vendor', 'ResizeImage', array('file' => 'thumbnail' . DS . 'ThumbLib.inc.php'));
         $this->Img = $this->Components->load('Img');
         $targetdir = WWW_ROOT . 'images/original';
         if (!empty($this->request->data['Product']['image']['name'])) {
             $ext = $this->Img->ext($this->request->data['Product']['image']['name']);
             $origFile = 'meal' . time() . '.' . $ext;
             if (file_exists($targetdir . $this->request->data['Product']['image_name'])) {
                 @unlink($targetdir . $this->request->data['Product']['image_name']);
             }
             if (file_exists(WWW_ROOT . 'images/large/' . $this->request->data['Product']['image_name'])) {
                 @unlink(WWW_ROOT . 'images/large/' . $this->request->data['Product']['image_name']);
             }
             if (file_exists(WWW_ROOT . 'images/small/' . $this->request->data['Product']['image_name'])) {
                 @unlink(WWW_ROOT . 'images/small/' . $this->request->data['Product']['image_name']);
             }
             $upload = $this->Img->upload($this->request->data['Product']['image']['tmp_name'], $targetdir, $origFile);
             if ($upload == 'Success') {
                 //$this->Img->resampleGD($targetdir . DS . $origFile, WWW_ROOT . 'images/large/', $origFile, 368, 328, 1, 0);
                 // $this->Img->resampleGD($targetdir . DS . $origFile, WWW_ROOT . 'images/small/', $origFile, 295, 295, 1, 0);
                 $resize = new ResizeImage($targetdir . DS . $origFile);
                 $resize->resizeTo(295, 295, 'exact');
                 $resize->saveImage(WWW_ROOT . 'images/small/' . $origFile);
                 $resize->resizeTo(368, 328, 'exact');
                 $resize->saveImage(WWW_ROOT . 'images/large/' . $origFile);
                 $this->request->data['Product']['image'] = $origFile;
             }
         } else {
             $this->request->data['Product']['image'] = $this->request->data['Product']['image_name'];
         }
         if ($this->Product->save($this->request->data)) {
             $this->Session->setFlash($upload);
             return $this->redirect(array('controller' => 'products', 'action' => 'index', 'admin' => true));
         } else {
             $this->Session->setFlash('The Product could not be saved. Please, try again.');
         }
     } else {
         $product = $this->Product->find('first', array('conditions' => array('Product.id' => $id)));
         $this->request->data = $product;
     }
     $this->set(compact('product'));
     $brands = $this->Product->Brand->find('list');
     $this->set(compact('brands'));
     $categories = $this->Product->Category->generateTreeList(null, null, null, '--');
     $this->set(compact('categories'));
     /*$productmods = $this->Product->Productmod->find('all', array(
           'conditions' => array(
               'Productmod.product_id' => $product['Product']['id']
           )
       ));
       $this->set(compact('productmods'));*/
     $users = $this->Product->User->find('list', array('conditions' => array('User.role' => 'cook'), 'fields' => array('id', 'first_name')));
     //pr($users);
     $this->set(compact('users'));
 }
 public function updateUser()
 {
     if (isset($_POST['submit'])) {
         //            var_dump($_POST['pass']) ;
         if ($_POST['nip'] == "" || $_POST['nama'] == "") {
             echo 'ada field yang masih belum diisi';
         } else {
             if ($_POST['pass'] !== $_POST['cpass']) {
                 echo 'data tidak bisa disimpan karena password berbeda dengan confirm passwordnya';
             }
             if ($_POST['pass'] == "no_change" || $_POST['cpass'] == "no_change") {
                 if ($_FILES['upload']['name'] == "") {
                     $user = new User($registry);
                     $user->set_id($_POST['id']);
                     $user->set_nip($_POST['nip']);
                     $user->set_nmUser($_POST['nama']);
                     $user->set_akses($_POST['akses']);
                     $user->updateUser_withoutpass($user);
                 } else {
                     $allowedExts = array("jpg", "jpeg", "png");
                     $ext = explode('.', $_FILES['upload']['name']);
                     $extension = $ext[count($ext) - 1];
                     if (in_array($extension, $allowedExts)) {
                         $img_small = new ResizeImage($_FILES["upload"]["tmp_name"]);
                         $img_small->resizeTo(64, $resizeOption = 'maxwidth');
                         $img_small->saveImage("files/foto/" . $_POST['nip'] . "_small." . $extension);
                         move_uploaded_file($_FILES["upload"]["tmp_name"], "files/foto/" . $_POST['nip'] . "." . $extension);
                     } else {
                     }
                     $user = new User($registry);
                     $user->set_id($_POST['id']);
                     $user->set_nip($_POST['nip']);
                     $user->set_nmUser($_POST['nama']);
                     $user->set_akses($_POST['akses']);
                     $user->set_foto($_POST['nip'] . "." . $extension);
                     $user->updateUser_withoutpass($user);
                 }
             }
             if ($_POST['pass'] !== "no_change" && $_POST['pass'] == $_POST['cpass']) {
                 if ($_FILES['upload']['name'] == "") {
                     $user = new User($registry);
                     $user->set_id($_POST['id']);
                     $user->set_nip($_POST['nip']);
                     $user->set_nmUser($_POST['nama']);
                     $user->set_pass($_POST['pass']);
                     $user->set_akses($_POST['akses']);
                     $user->updateUser($user);
                 } else {
                     $allowedExts = array("jpg", "jpeg", "png");
                     $ext = explode('.', $_FILES['upload']['name']);
                     $extension = $ext[count($ext) - 1];
                     if (in_array($extension, $allowedExts)) {
                         $img_small = new ResizeImage($_FILES["upload"]["tmp_name"]);
                         $img_small->resizeTo(64, $resizeOption = 'maxwidth');
                         $img_small->saveImage("files/foto/" . $_POST['nip'] . "_small." . $extension);
                         move_uploaded_file($_FILES["upload"]["tmp_name"], "files/foto/" . $_POST['nip'] . "." . $extension);
                     } else {
                     }
                     $user = new User($registry);
                     $user->set_id($_POST['id']);
                     $user->set_nip($_POST['nip']);
                     $user->set_nmUser($_POST['nama']);
                     $user->set_pass($_POST['pass']);
                     $user->set_akses($_POST['akses']);
                     $user->set_foto($_POST['nip'] . "." . $extension);
                     $user->updateUser($user);
                 }
             }
         }
     }
     header('location:' . URL . 'admin/listUser');
 }
Exemple #23
0
 protected function afterGetContentBody()
 {
     $sn = time();
     $tmpFile = $temp = Yii::app()->params['temp'];
     $storage = Yii::app()->params['feed_path'];
     $cdn = Yii::app()->params['cdn_url'];
     $contentParttern = $this->config['content_pattern'];
     $contentPage = '';
     $k = 0;
     foreach ($this->html->find("{$contentParttern} .item-list ul li") as $e) {
         $k++;
     }
     if ($k > 0) {
         $numPage = $k - 1;
         for ($j = 2; $j < $numPage; $j++) {
             $link = $this->url . '&page=' . $j;
             echo $link . "\n";
             $htmlBodyPage = file_get_html($link);
             if (is_object($htmlBodyPage)) {
                 if (isset($this->config['remove_pattern']) || !empty($this->config['remove_pattern'])) {
                     $removePattern = explode('|', $this->config['remove_pattern']);
                     foreach ($removePattern as $rpt) {
                         if ($rpt != '') {
                             foreach ($htmlBodyPage->find("{$rpt}") as $e) {
                                 $e->outertext = '';
                             }
                         }
                     }
                 }
                 foreach ($htmlBodyPage->find("a") as $e) {
                     $innerText = $e->plaintext;
                     $e->outertext = $innerText;
                     //$e->href = '#';
                 }
                 //get image for content
                 $i = 0;
                 foreach ($htmlBodyPage->find("{$contentParttern} img") as $e) {
                     $imgSrc = $e->src;
                     if (!empty($imgSrc)) {
                         $fileInfo = explode('.', $imgSrc);
                         $fileType = $fileInfo[count($fileInfo) - 1];
                         $fileName = 'tmp_' . $sn . $i . "." . $fileType;
                         $sfile = $tmpFile . DS . $fileName;
                         $res_get_file = FileRemote::getFromUrl($imgSrc, $sfile);
                         if ($res_get_file && file_exists($sfile)) {
                             $fileDest = StorageHelper::generalStoragePath($sn . $i, $fileType, $storage);
                             list($width, $height) = getimagesize($sfile);
                             if ($width > 500) {
                                 $width = 500;
                                 $height = 0;
                                 $resizeObj = new ResizeImage($sfile);
                                 $resizeObj->resizeImage($width, $height);
                                 $resizeObj->saveImage($fileDest, 100);
                             } else {
                                 $fileSystem = new Filesystem();
                                 $copy = $fileSystem->copy($sfile, $fileDest);
                             }
                             //resize image
                             unlink($sfile);
                             if (file_exists($fileDest)) {
                                 echo $fileDest . "\n";
                                 $fileDestUrl = str_replace($storage, $cdn, $fileDest);
                                 $fileDestUrl = str_replace(DS, "/", $fileDestUrl);
                                 echo $fileDestUrl . "\n";
                                 //$e->src = $fileDestUrl;
                                 $e->outertext = '<img src="' . $fileDestUrl . '" title="' . $e->title . '" alt="' . $e->alt . '" />';
                                 echo 'replace file content success in page' . $j . "\n";
                             } else {
                                 echo 'replace file content error' . "\n";
                             }
                         }
                         $i++;
                     }
                 }
                 $contentPage .= $htmlBodyPage->find($this->config['content_pattern'], 0)->innertext;
             }
         }
     }
     $this->content .= $contentPage;
 }