Example #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);
     }
 }
 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);
 }
Example #3
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);
 }
Example #4
0
function upload($uid, $uploadName = false, $FILE)
{
    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);
            $newWidth = $resize->imgw();
            $newHeight = $resize->imgh();
            /* We resize to reduce the file size of image */
            $resize->resizeTo($newWidth, $newHeight, 'exact');
            $resize->saveImage($path, 50);
            /* Get the image */
            $imgContent = file_get_contents($path);
            /* Encode the image file */
            $imgContent = base64_encode($imgContent);
            /* For Saving Database Space, we md5 the upload file name */
            $uploadMD5Name = md5($uploadName);
            /* Only do data insertion if the data doesn't exist, else update the already existing value */
            $sql = $OP->dbh->prepare("UPDATE `data` SET `txt`=? WHERE `uid`=? AND `name`=?");
            $sql->execute(array($imgContent, $uid, $uploadMD5Name));
            if ($sql->rowCount() == 0) {
                $sql = $OP->dbh->prepare("INSERT INTO `data` (`uid`, `name`, `txt`) VALUES (?, ?, ?)");
                $sql->execute(array($uid, $uploadMD5Name, $imgContent));
            }
            /* 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);
 }
Example #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();
         }
     }
 }
Example #7
0
 private function uploadAndResizeBanner()
 {
     $desktopFolder = 'images/banners/desktop';
     $tabletFolder = 'images/banners/tablet';
     $mobileFolder = 'images/banners/mobile';
     $fileTypes = array('image/jpeg', 'image/jpg', 'image/pjpeg');
     // instantialise the Upload class
     $upload = new Upload('banner_img', $fileTypes, $desktopFolder);
     $returnFile = $upload->isUploaded();
     // if no file has been uploaded then display error exit as nothing to resize
     if (!$returnFile) {
         $result['image_error'] = $upload->msg;
         $result['resized'] = false;
         return $result;
     }
     // there is a file so resize, first set the file paths for all images
     $fileName = basename($returnFile);
     $desktopPath = $desktopFolder . '/' . $fileName;
     $tabletPath = $tabletFolder . '/' . $fileName;
     $mobilePath = $mobileFolder . '/' . $fileName;
     // copy file to all other folders folders
     copy($returnFile, $tabletPath);
     copy($returnFile, $mobilePath);
     // if copy fails then exit
     if (!file_exists($tabletPath) || !file_exists($mobilePath)) {
         return false;
     }
     $imgInfo = getimagesize($returnFile);
     // resize image to 960px by 290px for the desktop
     $resizePhoto = new ResizeImage($desktopPath, '', $desktopFolder, '960', '290');
     // if the resize to 200px is unsuccessful
     if (!$resizePhoto->resize()) {
         //			 echo 'Unable to resize image to 960 pixels'; // (development only)
     }
     // resize image to 735px by 222px for tablet
     $resizePhoto1 = new ResizeImage($tabletPath, '', $tabletFolder, '735', '222');
     // if the resize to 300px is unsuccessful
     if (!$resizePhoto1->resize()) {
         //			 echo 'Unable to resize image to 735 pixels'; // (development only)
     }
     // resize image to 320px by 160px for mobile
     $resizePhoto2 = new ResizeImage($mobilePath, '', $mobileFolder, '320', '160');
     // if the resize to 400px is unsuccessful
     if (!$resizePhoto2->resize()) {
         //			 echo 'Unable to resize image to 320 pixels'; // (development only)
     }
     // if the new resized thumb, the tablet and the desktop image exist it worked so return['ok'] true!
     if (file_exists($mobilePath) && file_exists($tabletPath) && file_exists($desktopPath)) {
         $result['banner_img'] = basename($mobilePath);
         $result['resized'] = true;
         return $result;
     } else {
         return false;
     }
 }
Example #8
0
 // We only server PNG images
 /* Caching Headers */
 $etag = hash("md5", $fileName . $fileCrop);
 header("ETag: {$etag}");
 /* Was it already cached before by the browser ? The old etag will be sent by the browsers as HTTP_IF_NONE_MATCH. We interpret it */
 $_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);
Example #9
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();
         }
     }
 }
<?php

require 'ResizeImage.php';
$ResizeImage = new ResizeImage();
$ResizeImage->setImageToResize("Desert.jpg");
$ResizeImage->setNewWidth('300');
$ResizeImage->setNewHeight('300');
$ResizeImage->setRatio(true);
$ResizeImage->setNewImageName('Desert_resized');
$ResizeImage->setSaveFolder(__DIR__ . DIRECTORY_SEPARATOR);
$result = $ResizeImage->resize();
print_r($result);
Example #11
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();
         }
     }
 }
Example #12
0
 /**
  * 裁剪指定图片
  *
  * @param string $field 上传表单名
  * @return bool
  */
 public function create_thumb($pic_path)
 {
     if (!file_exists($pic_path)) {
         return;
     }
     //是否需要生成缩略图
     $ifresize = false;
     if ($this->thumb_width && $this->thumb_height && $this->thumb_ext) {
         $thumb_width = explode(',', $this->thumb_width);
         $thumb_height = explode(',', $this->thumb_height);
         $thumb_ext = explode(',', $this->thumb_ext);
         if (count($thumb_width) == count($thumb_height) && count($thumb_height) == count($thumb_ext)) {
             $ifresize = true;
         }
     }
     $image_info = @getimagesize($pic_path);
     //计算缩略图的尺寸
     if ($ifresize) {
         for ($i = 0; $i < count($thumb_width); $i++) {
             $imgscaleto = $thumb_width[$i] == $thumb_height[$i];
             if ($image_info[0] < $thumb_width[$i]) {
                 $thumb_width[$i] = $image_info[0];
             }
             if ($image_info[1] < $thumb_height[$i]) {
                 $thumb_height[$i] = $image_info[1];
             }
             $thumb_wh = $thumb_width[$i] / $thumb_height[$i];
             $src_wh = $image_info[0] / $image_info[1];
             if ($thumb_wh <= $src_wh) {
                 $thumb_height[$i] = $thumb_width[$i] * ($image_info[1] / $image_info[0]);
             } else {
                 $thumb_width[$i] = $thumb_height[$i] * ($image_info[0] / $image_info[1]);
             }
             if ($imgscaleto) {
                 $scale[$i] = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
             } else {
                 $scale[$i] = 0;
             }
         }
     }
     //产生缩略图
     if ($ifresize) {
         $resizeImage = new ResizeImage();
         $save_path = rtrim(BASE_UPLOAD_PATH . DS . $this->save_path, '/');
         for ($i = 0; $i < count($thumb_width); $i++) {
             //				$resizeImage->newImg($save_path.DS.$this->file_name,$thumb_width[$i],$thumb_height[$i],$scale[$i],$thumb_ext[$i].'.',$save_path,$this->filling);
             $resizeImage->newImg($pic_path, $thumb_width[$i], $thumb_height[$i], $scale[$i], $thumb_ext[$i] . '.', dirname($pic_path), $this->filling);
         }
     }
 }
     $data = escape($data);
     $j = new Jobs($id);
     $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();
Example #14
0
 /**
  * 上传操作
  *
  * @param string $field 上传表单名
  * @return bool
  */
 public function upfile($field)
 {
     //上传文件
     $this->upload_file = $_FILES[$field];
     if ($this->upload_file['tmp_name'] == "") {
         $this->setError(Language::get('cant_find_temporary_files'));
         return false;
     }
     //对上传文件错误码进行验证
     $error = $this->fileInputError();
     if (!$error) {
         return false;
     }
     //验证是否是合法的上传文件
     if (!is_uploaded_file($this->upload_file['tmp_name'])) {
         $this->setError(Language::get('upload_file_attack'));
         return false;
     }
     //验证文件大小
     if ($this->upload_file['size'] == 0) {
         $error = Language::get('upload_file_size_none');
         $this->setError($error);
         return false;
     }
     if ($this->upload_file['size'] > $this->max_size * 1024) {
         $error = Language::get('upload_file_size_cant_over') . $this->max_size . 'KB';
         $this->setError($error);
         return false;
     }
     //文件后缀名
     $tmp_ext = explode(".", $this->upload_file['name']);
     $tmp_ext = $tmp_ext[count($tmp_ext) - 1];
     $this->ext = strtolower($tmp_ext);
     //验证文件格式是否为系统允许
     if (!in_array($this->ext, $this->allow_type)) {
         $error = Language::get('image_allow_ext_is') . implode(',', $this->allow_type);
         $this->setError($error);
         return false;
     }
     //检查是否为有效图片
     if (!($image_info = @getimagesize($this->upload_file['tmp_name']))) {
         $error = Language::get('upload_image_is_not_image');
         $this->setError($error);
         return false;
     }
     //设置图片路径
     $this->save_path = $this->setPath();
     //设置文件名称
     if (empty($this->file_name)) {
         $this->setFileName();
     }
     //是否需要生成缩略图
     $ifresize = false;
     if ($this->thumb_width && $this->thumb_height && $this->thumb_ext) {
         $thumb_width = explode(',', $this->thumb_width);
         $thumb_height = explode(',', $this->thumb_height);
         $thumb_ext = explode(',', $this->thumb_ext);
         if (count($thumb_width) == count($thumb_height) && count($thumb_height) == count($thumb_ext)) {
             $ifresize = true;
         }
     }
     //计算缩略图的尺寸
     if ($ifresize) {
         for ($i = 0; $i < count($thumb_width); $i++) {
             $imgscaleto = $thumb_width[$i] == $thumb_height[$i];
             if ($image_info[0] < $thumb_width[$i]) {
                 $thumb_width[$i] = $image_info[0];
             }
             if ($image_info[1] < $thumb_height[$i]) {
                 $thumb_height[$i] = $image_info[1];
             }
             $thumb_wh = $thumb_width[$i] / $thumb_height[$i];
             $src_wh = $image_info[0] / $image_info[1];
             if ($thumb_wh <= $src_wh) {
                 $thumb_height[$i] = $thumb_width[$i] * ($image_info[1] / $image_info[0]);
             } else {
                 $thumb_width[$i] = $thumb_height[$i] * ($image_info[0] / $image_info[1]);
             }
             if ($imgscaleto) {
                 $scale[$i] = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
                 //					if ($this->config['thumb_type'] == 'gd'){
                 //						$scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
                 //					}else{
                 //						$scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
                 //					}
             } else {
                 $scale[$i] = 0;
             }
             //				if ($thumb_width[$i] == $thumb_height[$i]){
             //					$scale[$i] = $thumb_width[$i];
             //				}else{
             //					$scale[$i] = 0;
             //				}
         }
     }
     //是否立即弹出错误
     if ($this->if_show_error) {
         echo "<script type='text/javascript'>alert('" . ($this->if_show_error_one ? $error : $this->error) . "');history.back();</script>";
         die;
     }
     if ($this->error != '') {
         return false;
     }
     if (@move_uploaded_file($this->upload_file['tmp_name'], BASE_UPLOAD_PATH . DS . $this->save_path . DS . $this->file_name)) {
         //产生缩略图
         if ($ifresize) {
             $resizeImage = new ResizeImage();
             $save_path = rtrim(BASE_UPLOAD_PATH . DS . $this->save_path, '/');
             for ($i = 0; $i < count($thumb_width); $i++) {
                 $resizeImage->newImg($save_path . DS . $this->file_name, $thumb_width[$i], $thumb_height[$i], $scale[$i], $thumb_ext[$i] . '.', $save_path, $this->filling);
                 if ($i == 0) {
                     $resize_image = explode('/', $resizeImage->relative_dstimg);
                     $this->thumb_image = $resize_image[count($resize_image) - 1];
                 }
             }
         }
         //删除原图
         if ($this->ifremove && is_file(BASE_UPLOAD_PATH . DS . $this->save_path . DS . $this->file_name)) {
             @unlink(BASE_UPLOAD_PATH . DS . $this->save_path . DS . $this->file_name);
         }
         return true;
     } else {
         $this->setError(Language::get('upload_file_fail'));
         return false;
     }
     //		$this->setErrorFileName($this->upload_file['tmp_name']);
     return $this->error;
 }
Example #15
0
        if (is_uploaded_file($_FILES["photo"]["tmp_name"])) {
            $fileName = $_FILES["photo"]["name"];
            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
Example #16
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;
         }
     }
 }
Example #17
0
 /**
  * 发布动态
  */
 public function actionTrends()
 {
     if (!isset($_POST['uid']) || !$_POST['uid']) {
         $this->_exit($this->_error['20007'], '20007');
     }
     if (!(isset($_POST['content']) && isset($_POST['image'])) || !($_POST['image'] || $_POST['content'])) {
         $this->_exit($this->_error['20056'], '20056');
     }
     if (!isset($_POST['area']) || !$_POST['area']) {
         $this->_exit($this->_error['20042'], '20042');
     }
     $uid = trim($_POST['uid']);
     $content = trim($_POST['content']);
     $area = trim($_POST['area']);
     $imgdata = $_POST['image'] ? trim($_POST['image']) : file_get_contents('php://input');
     if ($imgdata) {
         $ms = date('Ym', time());
         $path = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'trends' . DIRECTORY_SEPARATOR . $ms . DIRECTORY_SEPARATOR;
         $imgName = MD5(time() . $this->getPostCode()) . '.jpg';
         if (!is_dir($path)) {
             mkdir($path, 0755, true);
         }
         $newFilePath = $path . $imgName;
         $newFile = fopen($newFilePath, 'w');
         fwrite($newFile, $imgdata);
         fclose($newFile);
         $fileName = $ms . DIRECTORY_SEPARATOR . $imgName;
         include Yii::app()->basePath . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'ResizeImage.php';
         $m = new ResizeImage();
         $m->ResizeImg($newFilePath, '230', '230', '0', $path . '230x230-' . $imgName);
         $m->ResizeImg($newFilePath, '120', '120', '0', $path . '120x120-' . $imgName);
     } else {
         $fileName = '';
     }
     $img = trim($fileName);
     $res = Trends::model()->addTrends($uid, $area, $content, $img);
     if ($res) {
         $this->_exit($this->_error['20000'], '20000', array('img' => self::HOST_HTTP_TRENDS . str_replace('\\', '/', $img), 'tid' => $res), 'trends');
     }
     $this->_exit($this->_error['21000'], '21000');
 }
Example #18
0
 function UploadThumb($flv, $thumbid)
 {
     $file = $_FILES["upload_thumb_{$thumbid}"]['tmp_name'];
     $ext = GetExt($_FILES["upload_thumb_{$thumbid}"]['name']);
     if (!empty($file) && $ext == 'jpg') {
         $image = new ResizeImage();
         if ($image->ValidateImage($file, $ext)) {
             $thumb = BASEDIR . '/files/thumbs/' . GetThumb($flv, $thumbid);
             move_uploaded_file($file, $thumb);
             $image->CreateThumb($thumb, $thumb, THUMB_WIDTH, $ext, THUMB_HEIGHT, false);
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #19
0
 /**
  * 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;
     }
 }
Example #20
0
    $etag = hash("md5", $fileName . $fileCrop);
    header("ETag: {$etag}");
    /* Was it already cached before by the browser ? The old etag will be sent by the browsers as HTTP_IF_NONE_MATCH. We interpret it */
    $_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");
    }
    /* Get the original image file */
    $fileData = base64_decode($fileData);
    /* 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 */
        $total = $resize->imgw() + $resize->imgh();
        $newWidth = $resize->imgw() / $total * $fileCrop;
        $newHeight = $resize->imgh() / $total * $fileCrop;
        if ($newWidth > $resize->imgw() || $newHeight > $resize->imgh()) {
            $OP->ser();
        }
        /* Resize & Save */
        $resize->resizeTo($newWidth, $newHeight, 'exact');
        $resize->saveImage($temp, 80);
        $fileData = file_get_contents($temp);
    }
    /* Output the file data */
    echo $fileData;
}
<?php

error_reporting(0);
if (isset($_REQUEST['width']) && $_REQUEST['width'] != '') {
    $width = $_REQUEST['width'];
}
if (isset($_REQUEST['height']) && $_REQUEST['height'] != '') {
    $height = $_REQUEST['height'];
}
if ($height != '') {
    header('Content-Type: image/jpeg');
    include 'resizeimageclass.php';
    $image = new ResizeImage();
    $image->load($_REQUEST['path']);
    $image->resizeToHeight($height);
    $image->output();
}
if ($width != '') {
    header('Content-Type: image/jpeg');
    include 'resizeimageclass.php';
    $image = new ResizeImage();
    $image->load($_REQUEST['path']);
    $image->resizeToWidth($width);
    $image->output();
}
//                        header('Content-Type: image/jpeg');
//			include('resizeimageclass.php');
//			$image = new ResizeImage ();
//			$image->load($_REQUEST['path']);
//			$image->resizeToWidth($width);
//			$image->output();
 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 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'));
 }
Example #24
0
 /**
  * Upload file to server
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param boolean $isImage
  *
  * @return string
  */
 public static function uploadFile($file, $isImage = true)
 {
     $newFileName = self::createNewFileName($file->getClientOriginalName());
     $finalFileName = $newFileName . '.' . $file->getClientOriginalExtension();
     if ($isImage) {
         $uploadDir = self::getImageUploadPath();
         $returnFileName = $newFileName;
     } else {
         $uploadDir = self::getFileUploadPath();
         $returnFileName = $finalFileName;
     }
     // Upload file to server
     $uploadFile = $file->move($uploadDir, $finalFileName);
     if (empty($uploadFile)) {
         return '';
     }
     if ($isImage) {
         // Create thumbnail image
         $thumbWidth = Config::get('app.image_sizes.size.thumb');
         $thumbName = Config::get('app.image_sizes.name.thumb') . $finalFileName;
         copy($uploadDir . $finalFileName, $uploadDir . $thumbName);
         $thumbImage = ResizeImage::make($uploadDir . $thumbName);
         $thumbImage->orientate();
         $thumbImage->fit($thumbWidth)->save($uploadDir . $thumbName);
     }
     return $returnFileName;
 }
Example #25
0
 function upload_thumb($array)
 {
     global $file_name, $LANG;
     //Get File Name
     $file = $array['name'];
     $ext = getExt($file);
     $image = new ResizeImage();
     if (!empty($file) && file_exists($array['tmp_name']) && !error()) {
         if ($image->ValidateImage($array['tmp_name'], $ext)) {
             $file = BASEDIR . '/files/thumbs/' . $_POST['file_name'] . '.' . $ext;
             $bfile = BASEDIR . '/files/thumbs/' . $_POST['file_name'] . '.-big.' . $ext;
             if (!file_exists($file)) {
                 move_uploaded_file($array['tmp_name'], $file);
                 $image->CreateThumb($file, $bfile, config('big_thumb_width'), $ext, config('big_thumb_height'), false);
                 $image->CreateThumb($file, $file, THUMB_WIDTH, $ext, THUMB_HEIGHT, false);
             }
         } else {
             e(lang('vdo_thumb_up_err'));
         }
     } else {
         return true;
     }
 }
Example #26
0
 $target_path = $globalpath . "images/uploads/finaoimages/";
 $target_thumb = $globalpath . "images/uploads/finaoimages/thumbs/";
 $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;
Example #27
0
 /**
  * Ресайз и сохранение
  * @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);
     }
 }
 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;
 }
 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');
 }
Example #30
0
function resize_image($path, $save_path, $width, $height)
{
    $image = new ResizeImage($path);
    $image->resizeTo($width, $height, 'exact');
    $image->saveImage($save_path);
}