Exemplo n.º 1
0
 function UploadImage()
 {
     //$this->GotoLogin();
     $name = $_FILES['Filedata']['name'];
     $id = rand(10, 10000000);
     $rpath = 'images/building/face/' . face_path($id);
     $image_path = __WEB_ROOT . '/' . $rpath;
     $image_name = $id . '_o.jpg';
     $image_file = $rpath . $image_name;
     $image_file_s = $rpath . $id . '_s.jpg';
     $image_file_t = $rpath . $id . '_t.jpg';
     $image_file_p = $rpath . $id . '_p.jpg';
     $pic_field = 'Filedata';
     $UploadHandler = new UploadHandler($_FILES, $image_path, $pic_field, true, false);
     $UploadHandler->setMaxSize(2048);
     $UploadHandler->setNewName($image_name);
     $ret = $UploadHandler->doUpload();
     if (!$ret) {
         $rets = $UploadHandler->getError();
         $ret = $rets ? implode(" ", (array) $rets) : 'image upload is invalid';
         $r = array('error' => $ret, 'code' => -5);
         if ($r['code'] < 0 && $r['error']) {
             $this->_image_error($rets['error']);
         }
     }
     list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_file);
     if ($image_width >= 120 && $image_height <= 120) {
         resizeimage($image_file, $image_file_s, 120, 0, true);
     }
     if ($image_height >= 120 && $image_height <= 120) {
         resizeimage($image_file, $image_file_s, 0, 120, true);
     }
     if ($image_height > 120 && $image_width > 120 && $image_width > $image_height) {
         resizeimage($image_file, $image_file_s, 120, 0, true);
     }
     if ($image_height > 120 && $image_width > 120 && $image_width < $image_height) {
         resizeimage($image_file, $image_file_s, 0, 120, true);
     }
     resizeimage($image_file, $image_file_t, 600, 0, true);
     resizeimage($image_file, $image_file_p, 180, 180, false);
     $result = array();
     $result['status'] = "ok";
     $result['image'] = $image_file;
     echo json_encode($result);
 }
Exemplo n.º 2
0
                }
                $mime = getimagesize($targetimg);
                $im = convert_image($targetimg, $mime['mime']);
                $newim = imagerotate($im, $degree, 0);
                imagedestroy($im);
                imagejpeg($newim, $targetimg, $tinybrowser['imagequality']);
                imagedestroy($newim);
                $rotateqty++;
                // delete and recreate thumbnail image
                $targetthumb = $tinybrowser['docroot'] . $editpath . "_thumbs/_" . $_POST['actionfile'][$rotatethis];
                if (file_exists($targetthumb)) {
                    unlink($targetthumb);
                }
                $mime = getimagesize($targetimg);
                $im = convert_image($targetimg, $mime['mime']);
                resizeimage($im, $tinybrowser['thumbsize'], $tinybrowser['thumbsize'], $targetthumb, $tinybrowser['thumbquality']);
                imagedestroy($im);
            } else {
                $errorqty++;
            }
        }
    }
}
// Read directory contents and populate $file array
$dh = opendir($tinybrowser['docroot'] . $editpath);
$file = array();
while (($filename = readdir($dh)) !== false) {
    if ($filename != "." && $filename != ".." && !is_dir($tinybrowser['docroot'] . $editpath . $filename)) {
        // search file name if search term entered
        if ($findnow) {
            $exists = stripos($filename, $findnow);
Exemplo n.º 3
0
				if($typenow=='image' && $imginfo = getimagesize($tinybrowser['docroot'].$browsepath.$filename))
					{
					$file['width'][] = $imginfo[0];
					$file['height'][] = $imginfo[1];
					$file['dimensions'][] = $imginfo[0] + $imginfo[1];
					$file['type'][] = $imginfo['mime'];

					// Check a thumbnail exists
					if(!file_exists($tinybrowser['docroot'].$browsepath.'_thumbs/')) createfolder($tinybrowser['docroot'].$browsepath.'_thumbs/',$tinybrowser['unixpermissions']);
			  		$thumbimg = $tinybrowser['docroot'].$browsepath.'_thumbs/_'.$filename;
					if (!file_exists($thumbimg))
						{
						$nothumbimg = $tinybrowser['docroot'].$browsepath.$filename;
						$mime = getimagesize($nothumbimg);
						$im = convert_image($nothumbimg,$mime['mime']);
						resizeimage($im,$tinybrowser['thumbsize'],$tinybrowser['thumbsize'],$thumbimg,$tinybrowser['thumbquality'],$mime['mime']);
						imagedestroy($im);
						$newthumbqty++;
						}
					}
				else
					{
					$file['width'][] = 'N/A';
					$file['height'][] = 'N/A';
					$file['dimensions'][] = 'N/A';
					$file['type'][] = returnMIMEType($filename);
					}
				}
			}
		}
	closedir($dh);
     $picture = $timestamp . $ext;
     if ($pic_database) {
         if (!move_uploaded_file_todb($_FILES["picture_add"]["tmp_name"], $picture, $type)) {
             died("Could NOT copy the file!");
         }
     } else {
         if (!move_uploaded_file($_FILES["picture_add"]["tmp_name"], "{$bazar_dir}/{$pic_path}/{$picture}")) {
             died("Could NOT copy the file!<br>({$bazar_dir}/{$pic_path}/{$picture})");
         }
     }
 } elseif (strtoupper($convertpath) == "GDLIB") {
     // advanced file handling with gdlib
     $picture = $timestamp . ".jpg";
     $_picture = "_" . $timestamp . ".jpg";
     resizeimage($_FILES["picture_add"]["tmp_name"], "{$bazar_dir}/{$pic_path}/{$picture}", $pic_res, $pic_quality);
     resizeimage($_FILES["picture_add"]["tmp_name"], "{$bazar_dir}/{$pic_path}/{$_picture}", $pic_lowres, $pic_quality);
     if ($pic_database) {
         if (!move_uploaded_file_todb("{$bazar_dir}/{$pic_path}/{$picture}", $picture, $type)) {
             died("Could NOT copy the file!");
         }
         suppr("{$bazar_dir}/{$pic_path}/{$picture}");
         if (!move_uploaded_file_todb("{$bazar_dir}/{$pic_path}/{$_picture}", $_picture, $type)) {
             died("Could NOT copy the file!");
         }
         suppr("{$bazar_dir}/{$pic_path}/{$_picture}");
     }
 } elseif ($convertpath) {
     // advanced file handling with convert
     if (!is_file($convertpath)) {
         died("Convertpath is wrong! Check configuration");
     }
Exemplo n.º 5
0
                // image specific info or general
                if ($typenow == 'image' && ($imginfo = getimagesize($_SESSION['tinybrowser']['docroot'] . $browsepath . $filename))) {
                    $file['width'][] = $imginfo[0];
                    $file['height'][] = $imginfo[1];
                    $file['dimensions'][] = $imginfo[0] + $imginfo[1];
                    $file['type'][] = $imginfo['mime'];
                    // Check a thumbnail exists
                    if (!file_exists($_SESSION['tinybrowser']['docroot'] . $browsepath . '_thumbs/')) {
                        createfolder($_SESSION['tinybrowser']['docroot'] . $browsepath . '_thumbs/', $_SESSION['tinybrowser']['unixpermissions']);
                    }
                    $thumbimg = $_SESSION['tinybrowser']['docroot'] . $browsepath . '_thumbs/_' . $filename;
                    if (!file_exists($thumbimg)) {
                        $nothumbimg = $_SESSION['tinybrowser']['docroot'] . $browsepath . $filename;
                        $mime = getimagesize($nothumbimg);
                        $im = convert_image($nothumbimg, $mime['mime']);
                        resizeimage($im, $_SESSION['tinybrowser']['thumbsize'], $_SESSION['tinybrowser']['thumbsize'], $thumbimg, $_SESSION['tinybrowser']['thumbquality'], $mime['mime']);
                        imagedestroy($im);
                        $newthumbqty++;
                    }
                } else {
                    $file['width'][] = 'N/A';
                    $file['height'][] = 'N/A';
                    $file['dimensions'][] = 'N/A';
                    $file['type'][] = returnMIMEType($filename);
                }
            }
        }
    }
    closedir($dh);
} elseif ($_SESSION['tinybrowser']['sessionsecured'] == true && isset($_SESSION[$_SESSION['tinybrowser']['sessioncheck']])) {
    // Check request tokens
 function upload_media($media_type, $entity_type = '', $entity_id = '', $id = '')
 {
     //prep form data
     $_POST['accountid'] = sess_var('accountid');
     if (!$id) {
         $_POST['entitytype'] = $entity_type;
         $_POST['entityid'] = $entity_id;
     }
     //if not edit (i.e add) or there is upload file then upload else just insert
     if (!$id || $_FILES['userfile']['name']) {
         $config['upload_path'] = 'resources/' . $media_type . '/';
         switch ($media_type) {
             case "files":
                 $allowed_types = "*";
                 $max_size = "16384";
                 break;
             case "images":
                 $allowed_types = "jpg|png|gif";
                 $max_size = "3072";
                 break;
             case "videos":
                 $allowed_types = "flv|mp4|mov";
                 $max_size = "16384";
                 break;
         }
         $config['allowed_types'] = $allowed_types;
         $config['max_size'] = $max_size;
         $this->load->library('upload', $config);
         //if error upload return error
         if (!$this->upload->do_upload()) {
             //ajax data array
             $data = array('is_valid' => 0, 'error' => $this->upload->display_errors());
             //echo str_replace('\\/', '/', json_encode($data));
             echo json_encode($data);
             return;
         } else {
             $file_data = $this->upload->data();
             $_POST['path'] = base_url() . $config['upload_path'];
             $_POST['name'] = $file_data['file_name'];
             $_POST['size'] = $file_data['file_size'];
             //reize images
             $this->load->helper("resize_image");
             if ($media_type == "images") {
                 resizeimage($file_data['full_path'], 136, 102, 80, "crop", $config['upload_path'] . "thumbs/" . $_POST['name']);
                 //so that not to enlarge the image in medium version
                 if ($file_data['image_width'] > 800 || $file_data['image_height'] > 600) {
                     resizeimage($file_data['full_path'], 800, 600, 80, "scale", $config['upload_path'] . "med/" . $_POST['name']);
                 } else {
                     copy($file_data['full_path'], $config['upload_path'] . "med/" . $_POST['name']);
                 }
             } else {
                 if ($media_type == "videos" && $_FILES['userfile2']['name']) {
                     $config2['upload_path'] = 'resources/videos/thumbs/';
                     $config2['allowed_types'] = 'jpg|png|gif';
                     $config2['max_size'] = '1024';
                     $this->upload->initialize($config2);
                     //if error upload return error
                     if (!$this->upload->do_upload('userfile2')) {
                         //ajax data array
                         $data = array('is_valid' => 0, 'error2' => $this->upload->display_errors());
                         echo json_encode($data);
                         //delete the video file if it was uploaded
                         if (is_file($config['upload_path'] . '/' . $_POST['name'])) {
                             unlink($config['upload_path'] . '/' . $_POST['name']);
                         }
                         return;
                     } else {
                         $file_data = $this->upload->data();
                         $_POST['thumb'] = $file_data['file_name'];
                         //resize thumbnail image
                         resizeimage($file_data['full_path'], 90, 65, 80, "crop", $file_data['full_path']);
                     }
                 }
             }
             //if edit (get old file name then delete after the insert)
             if ($id) {
                 $result = $this->media_model->get_name($media_type, $id);
                 $file_name = $result['name'];
                 $thumb = $result['thumb'];
             }
         }
     }
     //end if
     /*********** insert record into database ***********/
     //if edit
     if ($id) {
         $error = $this->media_model->update($media_type, $id);
         $content = $media_type . " has been UPDATED successfully";
     } else {
         $error = $this->media_model->add($media_type);
         $content = $media_type . " has been ADDED successfully";
     }
     if (!$error) {
         //if edit then delete old file
         if ($id && $_FILES['userfile']['name']) {
             if (is_file($config['upload_path'] . $file_name)) {
                 unlink($config['upload_path'] . $file_name);
             }
             if ($media_type == "images") {
                 if (is_file($config['upload_path'] . "thumbs/" . $file_name)) {
                     unlink($config['upload_path'] . "thumbs/" . $file_name);
                 }
                 if (is_file($config['upload_path'] . "med/" . $file_name)) {
                     unlink($config['upload_path'] . "med/" . $file_name);
                 }
             }
             if ($media_type == "videos" && $_FILES['userfile2']['name']) {
                 if (is_file($config['upload_path'] . "thumbs/" . $thumb)) {
                     unlink($config['upload_path'] . "thumbs/" . $thumb);
                 }
             }
         }
         //ajax data array
         $data = array('is_valid' => 1, 'content' => $content);
         echo json_encode($data);
     }
 }
Exemplo n.º 7
0
 $fz1280 = $path . '1_' . $sourimgname . '_1280.jpg';
 if (copy($save, $fz60)) {
     //更改图片大小
     resizeimage($fz60, 60, 60, $fz60);
 }
 if (copy($save, $fz240)) {
     //更改图片大小
     resizeimage($fz240, 240, 240, $fz240);
 }
 if (copy($save, $fz360)) {
     //更改图片大小
     resizeimage($fz360, 360, 360, $fz360);
 }
 if (copy($save, $fz1280)) {
     //更改图片大小
     resizeimage($fz1280, 1280, 1280, $fz1280);
 }
 //数据库信息
 $conn1 = mysql_connect($tbconfig['datahost'], $tbconfig['datausername'], $tbconfig['datauserpass'], true) or die('连接数据库失败');
 mysql_select_db($tbconfig['databasename'], $conn1);
 //用到的表
 $tablegoods = $tbconfig['datatablepre'] . 'goods';
 $tablegoodscommon = $tbconfig['datatablepre'] . 'goods_common';
 $tablegoodsimages = $tbconfig['datatablepre'] . 'goods_images';
 $tablealbum_pic = $tbconfig['datatablepre'] . 'album_pic';
 //更新goods表
 $updategoodssql = "UPDATE {$tablegoods} SET goods_image='" . $rukuimgname . "' WHERE goods_image='" . $sourimgname . "'";
 //更新goods_common表
 $updategoodscomsql = "UPDATE {$tablegoodscommon} SET goods_image='" . $rukuimgname . "' WHERE goods_image='" . $sourimgname . "'";
 //更新goods_images表
 $updategoodsimgsql = "UPDATE {$tablegoodsimages} SET goods_image='" . $rukuimgname . "' WHERE goods_image='" . $sourimgname . "'";
Exemplo n.º 8
0
				<?php 
            $count++;
            ?>
				
				<!-- For each additional image Add an extra Pagination -->
				<div>
					
					<a href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
">
						<?php 
            echo resizeimage($image, $height, $width, $quality, 1, $post->post_title, $class = "");
            ?>
					</a>
					
					<span class="slidecaption captionfade">
						<a href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
">
								<?php 
            echo substr(get_the_excerpt(), 0, 162);
            ?>
						</a>
Exemplo n.º 9
0
 function store($id, $tmpfile, $name)
 {
     // TODO : error codes
     // TODO : check file size
     global $DB;
     $bad_chars = array('\\.', '\\\\', "'", ' ', '\\/', ':', '\\*', '\\?', '"', '<', '>', '|');
     $allowed_extensions = array('jpeg', 'jpg', 'png', 'gif');
     $allowed_mimes = array('image/jpeg', 'image/png', 'image/gif');
     $format_ok = false;
     //First, does the file have valid name ?
     $reg = "/^(.[^" . implode('', $bad_chars) . "]+)\\.(" . implode('|', $allowed_extensions) . ")\$/i";
     if (preg_match($reg, $name, $matches)) {
         $format_ok = true;
         $extension = $matches[2];
     } else {
         return false;
     }
     //Second, let's see if the mime-type is allowed - if gd is aivailable
     if (function_exists("gd_info")) {
         $current = getimagesize($tmpfile);
         if (!in_array($current['mime'], $allowed_mimes)) {
             return false;
         }
     }
     $sql = "DELETE FROM " . PREFIX_DB . "pictures\n\t\t\t\tWHERE id_adh='" . $id . "'";
     $DB->Execute($sql);
     picture::delete($id);
     $new_file = dirname(__FILE__) . '/../photos/' . $id . '.' . $extension;
     move_uploaded_file($tmpfile, $new_file);
     // resize (if gd available)
     if (function_exists("gd_info")) {
         resizeimage($new_file, $new_file, 200, 200);
     }
     $f = fopen($new_file, 'r');
     $picture = '';
     while ($r = fread($f, 8192)) {
         $picture .= $r;
     }
     fclose($f);
     $sql = "INSERT INTO " . PREFIX_DB . "pictures\n\t\t\t\t(id_adh, picture, format)\n\t\t\t\tVALUES ('" . $id . "',''," . $DB->Qstr($extension) . ")";
     if (!$DB->Execute($sql)) {
         return false;
     }
     if (!$DB->UpdateBlob(PREFIX_DB . 'pictures', 'picture', $picture, 'id_adh=' . $id)) {
         return false;
     }
     return true;
 }
Exemplo n.º 10
0
function resizeimage_wrapper_dbcache($reset = FALSE)
{
    global $bgcachexpire;
    global $user;
    #$userId = $user->uid;
    $bgcacheid = 'bg_' . md5($_GET['imgp'] . $_GET['imgw'] . $_GET['imgh']);
    #echo $bgcacheid;
    static $my_data;
    #echo '0.... ';
    if (!isset($my_data) || $reset) {
        if (!$reset && ($cache = cache_get($bgcacheid)) && !empty($cache->data)) {
            #$my_data = $cache->data; echo '-1.... ' . $my_data;
            $my_data = unserialize($cache->data);
        } else {
            // Do your expensive calculations here, and populate $my_data
            // with the correct stuff..
            $my_data = resizeimage($_GET['imgp'], $_GET['imgw'], $_GET['imgh']);
            #echo ' -2.... ' . $bgcachexpire . ' // ' . $my_data;
            # For some reason I could not use: mysql_escape_string($my_data)
            #cache_set($bgcacheid, 'cache', time() + $bgcachexpire, $my_data);
            cache_set($bgcacheid, $my_data, 'cache', time() + $bgcachexpire);
            # FOR DRUPAL6 MUST USE:
            #cache_set($bgcacheid,  $my_data, time() + $bgcachexpire); # For some reason I could not use: mysql_escape_string($my_data)
            $my_data = unserialize($my_data);
        }
    }
    return $my_data;
}
Exemplo n.º 11
0
        if ($newsize) {
            // detect silly sizes
            if ($newsize > $tinybrowser['thumbsize']) {
                // do image resize
                $targetimg = $tinybrowser['docroot'] . $editpath . $_POST['actionfile'][$sizethis];
                if (file_exists($targetimg)) {
                    $mime = getimagesize($targetimg);
                    if ($_POST['resizetype'][$sizethis] == 'width') {
                        $rw = $newsize;
                        $rh = $mime[1];
                    } else {
                        $rw = $mime[0];
                        $rh = $newsize;
                    }
                    $im = convert_image($targetimg, $mime['mime']);
                    resizeimage($im, $rw, $rh, $targetimg, $tinybrowser['imagequality'], $mime['mime']);
                    imagedestroy($im);
                    $resizeqty++;
                } else {
                    $errorqty++;
                }
            } else {
                $errorqty++;
            }
        }
    }
}
// Rotate any selected files
if (isset($_POST['rotatefile'])) {
    $imagerefresh = '?refresh=' . uniqid('');
    foreach ($_POST['rotatefile'] as $rotatethis => $direction) {
Exemplo n.º 12
0
            break;
    }
    imagedestroy($image);
    exit;
}
function getFormat($format)
{
    $ret = ['w' => 0, 'h' => 0];
    if (substr($format, 0, 1) == "/") {
        $format = substr($format, 1);
    }
    $info = explode("/", $format);
    $w_key = array_search("w", $info);
    if ($w_key !== false) {
        $ret['w'] = $info[$w_key + 1];
    }
    $h_key = array_search("h", $info);
    if ($h_key !== false) {
        $ret['h'] = $info[$h_key + 1];
    }
    return $ret;
}
$filename = $_GET['filename'];
$format = $_GET['format'];
if (!$filename || !$format) {
    echo "params filename  and  format must be assigned";
    exit;
}
$ret = getFormat($format);
resizeimage($filename, $ret['w'], $ret['h']);
Exemplo n.º 13
0
 function Upload()
 {
     $rpath = './images/temp';
     $pic_field = 'Filedata';
     $todeletedImage = $this->QueryString('todelete');
     //$image_path=__WEB_ROOT.'/'.$rpath;
     $IoHandler = new IoHandler();
     if (file_exists($todeletedImage)) {
         $IoHandler->DeleteFile($todeletedImage);
     }
     $name = $_FILES['Filedata']['name'];
     $image_file = $image_path . $name;
     $Images = new ImagesHandler('Filedata');
     $Images->saveDir = $rpath;
     $path = $Images->move_uploaded();
     if ($Images->errID && $Images->errID != 0) {
         $result['status'] = "failed";
         $result['message'] = $Images->errMsg;
     } else {
         resizeimage($path, $path, 400, 0, true);
         $result['status'] = "ok";
         $result['message'] = "图片上传成功";
         $item['item_id'] = 0;
         $item['item_name'] = "";
         $item['item_src'] = $path;
         $item['item_type'] = 'image';
         $result['item'] = $item;
     }
     echo urldecode(json_encode(ArrayToJson($result)));
 }
Exemplo n.º 14
0
function saveIronImage($get_url, $save_url)
{
    createDirIfNotExists2($save_url);
    $img_content = file_get_contents($get_url);
    file_put_contents($save_url, $img_content);
    resizeimage($save_url, 350);
}
Exemplo n.º 15
0
 function UploadAvatorFromApp()
 {
     $this->NoLoginAjaxReturn();
     $rpath = './images/temp';
     $IoHandler = new IoHandler();
     $Images = new ImagesHandler('Filedata');
     $Images->saveDir = $rpath;
     $path = $Images->move_uploaded();
     if (!file_exists($path)) {
         $result['status'] = "failed";
         $result['message'] = urlencode('头像裁剪失败,图片传输过程中丢失');
         echo urldecode(json_encode($result));
         exit;
     }
     $userInfo = $this->UserLogic->GetUser($this->User['uid']);
     $old_facePath = $userInfo["face_url"];
     $imgId = $this->ImgLogic->AddNewImage();
     $path1 = 'images/user/' . face_path($imgId);
     if (!file_exists($path1)) {
         $IoHandler->MakeDir($path1);
     }
     $prefix = $path1 . $imgId;
     resizeimage($path, $prefix . '_p.jpg', 180, 180, true);
     resizeimage($path, $prefix . '_s.jpg', 50, 50, true);
     //$IoHandler->CopyFile($path, $prefix.'_t.jpg');
     if (file_exists($prefix . '_s.jpg')) {
         $userdata = array();
         $userdata['face_url'] = $prefix . '_s.jpg';
         $ret = $this->UserLogic->UpdateUser2($userdata, $this->User['uid']);
         if ($old_facePath && $old_facePath != "" && file_exists($old_facePath)) {
             $IoHandler->DeleteFile($old_facePath);
             $ps = explode("_", $old_facePath);
             $old2 = $ps[0] . "_p.jpg";
             if (file_exists($old2)) {
                 $IoHandler->DeleteFile($old2);
             }
         }
     } else {
         $result['status'] = "failed";
         $result['message'] = urlencode('头像缩放出错');
         $result['item'] = $prefix . '_s.jpg';
         echo urldecode(json_encode($result));
         exit;
     }
     $this->ImgLogic->DeleteImage($imgId, "");
     $IoHandler->DeleteFile($path);
     $result['status'] = "ok";
     $result['face_url'] = $prefix . '_s.jpg';
     $result['message'] = urlencode('头像保存成功');
     echo urldecode(json_encode($result));
 }