public function setUp() { $this->con = 'tests'; $this->chainClass = 'Psc\\CMS\\UploadManager'; parent::setUp(); $this->manager = new UploadManager(NULL, $this->getDoctrinePackage(), UploadManager::createCache($this->dir = $this->getTestDirectory()->sub('tmp/'))); $this->dir->create()->wipe(); }
function testIO_Upload_UploadManager() { $base = dirname(__FILE__); $Uploadmanager = new UploadManager(); $path = "/tmp/sjack/tmp"; $filename = "filename.gif"; $Uploadmanager->SetDestinationDir("/tmp/test.file"); // // Uplaod from URL // $res = $Uploadmanager->UploadFromURL("http://webta.net/images/webta_guy.jpg"); $this->assertTrue($res, "File uploaded from URL"); print_r($GLOBALS['warnings']); $file = array("name" => $filename, "size" => 1023, "type" => "image/txt", "error" => 0); // check upload $res = $Uploadmanager->Upload($file); $this->assertFalse($res, "File not uploaded"); // check Generate Path $result = $Uploadmanager->BuildDir($path, $filename); $md5 = md5($filename); $newpath = $path . "/" . substr($md5, 0, 2) . "/" . substr($md5, 2, 2); $this->assertEqual($result, $newpath, "Result path is valid: {$result}"); // check SetDestination $Uploadmanager->SetDestinationDir($result . "/" . $filename); $this->assertTrue(is_dir($result), "Destination created {$result}"); $valid = array("txt", "jpeg", "tar", "rar", "zip", "gif"); $Uploadmanager->SetValidExtensions($valid); // check Validate function / must be public access //$res = $Uploadmanager->Validate(); //$this->assertFalse($res, "Uploaded File Not validated"); }
public static function upload($index, $destination, $name, $pictureFormats) { $upload = new Upload(); $upload->set_file($_FILES[$index]); $upload->set_name($name); $upload->set_directory($destination); $param = array('type' => 'return'); $return = UploadManager::upload($upload, $pictureFormats, $param); $json = json_decode($return, true); return $json['status'] == 'success'; }
$smarty->assign('upload_id', $_REQUEST['upload_id']); } } if (isset($_GET['success'])) { $token = new Token(); if ($token->parse($_GET['t'])) { $template = 'puploader_success.tpl'; $smarty->assign('status', unserialize($token->getValueBinary("s"))); $smarty->assign('filenames', unserialize($token->getValueBinary("f"))); } } elseif (isset($_POST['selected'])) { //we dont get the button :( $status = array(); $filenames = array(); foreach ($_POST['field'] as $key => $value) { $uploadmanager = new UploadManager(); $square = new GridSquare(); $files_key = str_replace('.', '_', $value); $filenames[$key] = $_FILES[$files_key]['name']; $ok = $square->setByFullGridRef($_POST['grid_reference'][$key]); if ($ok) { // set up attributes from uploaded data $uploadmanager->setSquare($square); $uploadmanager->setViewpoint($_POST['photographer_gridref'][$key]); $uploadmanager->setDirection($_POST['view_direction'][$key]); $uploadmanager->setUse6fig(stripslashes($_POST['use6fig'][$key])); $uploadmanager->setTaken($_POST['imagetaken'][$key]); $uploadmanager->setTitle(utf8_decode($_POST['title'][$key])); $uploadmanager->setTitle2(utf8_decode($_POST['title2'][$key])); if ($_POST['comment'][$key] != "comment[{$key}]") { //bug? in Picasa sends the name in the value if blank, useful! (but only seems to apply to textareas)
* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once 'geograph/global.inc.php'; if (isset($_GET['preview'])) { session_cache_limiter('none'); } else { require_once 'geograph/gridimage.class.php'; require_once 'geograph/gridsquare.class.php'; } require_once 'geograph/uploadmanager.class.php'; init_session(); $uploadmanager = new UploadManager(); //display preview image? if (isset($_GET['preview'])) { $uploadmanager->outputPreviewImage($_GET['preview']); exit; } list($usec, $sec) = explode(' ', microtime()); $GLOBALS['STARTTIME'] = (double) $usec + (double) $sec; $square = new GridSquare(); $smarty = new GeographPage(); if (!$USER->hasPerm("basic")) { $smarty->display('static_submit_intro.tpl'); exit; } if (isset($_SESSION['tab'])) { $selectedtab = $_SESSION['tab'];
/** * Load the component Upload. * * @param \Cx\Core\ContentManager\Model\Entity\Page $page The resolved page */ public function load(\Cx\Core\ContentManager\Model\Entity\Page $page) { global $objTemplate; $objUploadModule = new UploadManager(); $objUploadModule->getPage(); }
public function actionUpload() { $uptype = zmf::filterInput($_GET['type'], 't', 1); $logid = zmf::filterInput($_GET['id']); //所属对象 $reImgsize = zmf::filterInput($_GET['imgsize']); //返回图片的尺寸 $fileholder = zmf::filterInput($_GET['fileholder'], 't', 1); //上传控件的ID if (!isset($uptype) or !in_array($uptype, array('posts', 'siteinfo'))) { $this->jsonOutPut(0, '请设置上传所属类型' . $uptype); } if (Yii::app()->request->getParam('PHPSESSID')) { Yii::app()->session->close(); $res = Yii::app()->session->setSessionID(Yii::app()->request->getParam('PHPSESSID')); Yii::app()->session->open(); } if (Yii::app()->user->isGuest) { $this->jsonOutPut(0, '请先登录'); } if (!$fileholder) { $fileholder = 'filedata'; } if (!isset($_FILES[$fileholder]) || !is_uploaded_file($_FILES[$fileholder]["tmp_name"]) || $_FILES[$fileholder]["error"] != 0) { $this->jsonOutPut(0, '无效上传,请重试'); } $img = CUploadedFile::getInstanceByName($fileholder); $ext = $img->getExtensionName(); $size = $img->getSize(); if ($size > zmf::config('imgMaxSize')) { $this->jsonOutPut(0, '上传文件最大尺寸为:' . tools::formatBytes(zmf::config('imgMaxSize'))); } $upExt = zmf::config("imgAllowTypes"); if (!preg_match('/^(' . str_replace('*.', '|', str_replace(';', '', $upExt)) . ')$/i', $ext)) { $this->jsonOutPut(0, '上传文件扩展名必需为:' . $upExt); } $sizeinfo = getimagesize($_FILES[$fileholder]["tmp_name"]); if ($sizeinfo['0'] < zmf::config('imgMinWidth') or $sizeinfo[1] < zmf::config('imgMinHeight')) { $this->jsonOutPut(0, "要求上传的图片尺寸,宽不能不小于" . zmf::config('imgMinWidth') . "px,高不能小于" . zmf::config('imgMinHeight') . "px."); } $ctime = zmf::now(); $dir = zmf::uploadDirs($ctime, 'app', $uptype); zmf::createUploadDir($dir); $fileName = zmf::uuid() . '.' . $ext; $origin = $dir; if (move_uploaded_file($_FILES[$fileholder]["tmp_name"], $origin . $fileName)) { $data = array(); $status = Posts::STATUS_NOTPASSED; $data['uid'] = zmf::uid(); $data['logid'] = $logid; $data['filePath'] = $fileName; $data['fileDesc'] = ''; $data['classify'] = $uptype; $data['covered'] = '0'; $data['cTime'] = $ctime; $data['status'] = $status; $data['width'] = $sizeinfo[0]; $data['height'] = $sizeinfo[1]; $data['size'] = $size; $model = new Attachments(); $model->attributes = $data; if ($model->save()) { $attachid = $model->id; $returnImgDir = zmf::getUpExtraUrl($ctime); $saveName = $uptype . '/' . $returnImgDir . '/' . $fileName; $accessKey = zmf::config('qiniuAk'); $secretKey = zmf::config('qiniuSk'); $bucket = zmf::config('qiniuBucket'); if ($accessKey && $secretKey && $bucket) { $auth = new Auth($accessKey, $secretKey); $token = $auth->uploadToken($bucket); $uploadMgr = new UploadManager(); list($ret, $err) = $uploadMgr->putFile($token, $saveName, $origin . $fileName); if ($err !== null) { zmf::fp(var_export($err)); $this->jsonOutPut(0, '上传至云服务错误'); } } $returnimg = zmf::uploadDirs($ctime, 'site', $uptype) . $fileName; $returnimg = zmf::getThumbnailUrl($returnimg, '650', $uptype); $_attr = array('id' => $attachid, 'imgurl' => $returnimg); $html = ''; if ($uptype == 'posts') { //$html= $this->renderPartial('/posts/_addImg',array('data'=>$_attr),true); } $outPutData = array('status' => 1, 'attachid' => $attachid, 'imgsrc' => $returnimg, 'html' => $html); $json = CJSON::encode($outPutData); echo $json; } else { $this->jsonOutPut(0, '写入数据库错误'); } } }
break; case UPLOAD_ERR_CANT_WRITE: $smarty->assign('error', 'System Error: Can not write file - please let us know'); break; case UPLOAD_ERR_EXTENSION: $smarty->assign('error', 'System Error: Upload Blocked - please let us know'); break; default: $smarty->assign('error', 'We were unable to process your upload - please try again'); break; } } elseif (isset($_POST['finalise'])) { $status = array(); $filenames = array(); foreach ($_POST['upload_id'] as $key => $upload_id) { $uploadmanager = new UploadManager(); $square = new GridSquare(); $filenames[$key] = $_POST['title'][$key]; $ok = $square->setByFullGridRef($grid_reference = $_POST['grid_reference'][$key]); if ($ok) { // set up attributes from uploaded data $uploadmanager->setSquare($square); $uploadmanager->setViewpoint($_POST['photographer_gridref'][$key]); $uploadmanager->setDirection($_POST['view_direction'][$key]); $uploadmanager->setUse6fig(stripslashes($_POST['use6fig'][$key])); $uploadmanager->setTaken($_POST['imagetaken'][$key]); $uploadmanager->setTitle($_POST['title'][$key]); $uploadmanager->setTitle2($_POST['title2'][$key]); $uploadmanager->setLargestSize($_POST['largestsize'][$key]); $uploadmanager->setClearExif($_POST['clearexif']); //$uploadmanager->setClearExif($_POST['clearexif'][$key]);
* * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once 'geograph/global.inc.php'; if (isset($_GET['preview'])) { session_cache_limiter('none'); } else { require_once 'geograph/gridimage.class.php'; require_once 'geograph/gridsquare.class.php'; require_once 'geograph/gridimagetroubleticket.class.php'; } require_once 'geograph/uploadmanager.class.php'; init_session(); $uploadmanager = new UploadManager(); //display preview image? if (isset($_GET['preview'])) { $uploadmanager->outputPreviewImage($_GET['preview']); exit; } $smarty = new GeographPage(); //you must be logged in to request changes $USER->mustHavePerm("basic"); $template = 'resubmit.tpl'; $cacheid = ''; $image = new GridImage(); if (isset($_REQUEST['id'])) { $image->loadFromId($_REQUEST['id']); $isowner = $image->user_id == $USER->user_id ? 1 : 0; $isadmin = $USER->hasPerm('ticketmod') ? 1 : 0;
$template = "static_404.tpl"; } else { $image->altUrl = $image->_getOriginalpath(true, false, '_640x640'); $image->originalUrl = $image->_getOriginalpath(true, false); $image->originalSize = filesize($_SERVER['DOCUMENT_ROOT'] . $image->originalUrl); $style = $USER->getStyle(); $smarty->assign('maincontentclass', 'content_photo' . $style); $imagesize = $image->_getFullSize(); $sizes = array(); $widths = array(); $heights = array(); $showorig = false; if ($image->original_width) { $smarty->assign('original_width', $image->original_width); $smarty->assign('original_height', $image->original_height); $uploadmanager = new UploadManager(); list($destwidth, $destheight, $maxdim, $changedim) = $uploadmanager->_new_size($image->original_width, $image->original_height); if ($changedim) { $showorig = true; foreach ($CONF['show_sizes'] as $cursize) { list($destwidth, $destheight, $destdim, $changedim) = $uploadmanager->_new_size($image->original_width, $image->original_height, $cursize); if (!$changedim) { break; } $sizes[] = $cursize; $widths[] = $destwidth; $heights[] = $destheight; $maxdim = $destdim; } $maxdim = max($image->original_width, $image->original_height); }
function UploadPicture() { global $CONF; global $xml; global $USER; if (empty($_POST['userid']) || !intval($_POST['userid'])) { $xml['status'] = 'Not Logged In'; returnXML(); } else { $USER = new GeographUser(intval($_POST['userid'])); //TODO: check validation hash? if ($_POST['validation'] != md5($_POST['userid'] . '#' . $CONF['register_confirmation_secret'])) { $xml['status'] = 'User not verified'; returnXML(); } if (!$USER->user_id || !$USER->hasPerm('basic')) { $xml['status'] = 'Not authorised to post'; returnXML(); } } $um = new UploadManager(); $gs = new GridSquare(); // this is the check that we like the client and any image has // come in with the appropriate cc licence $ccl = $_POST['cclicence']; if ($ccl != "I grant you the permission to use this submission " . "under the terms of the Creative Commons by-sa-2.0 licence") { $xml['status'] = 'Bad client submission'; returnXML(); } // validate the grid square - we may be going back to the user // quickly here :-) $gs->setByFullGridRef($_POST['subject']); if ($gs->errormsg != "") { $xml['status'] = $gs->errormsg; returnXML(); } $takendate = strtotime_uk($_POST['date']); if ($takendate > time()) { $xml['status'] = "Date taken in future"; returnXML(); } // set up attributes from uploaded data $um->setSquare($gs); $um->setViewpoint($_POST['photographer']); $um->setDirection($_POST['direction']); $um->setTaken(date('Y-m-d', $takendate)); $um->setTitle($_POST['title']); $um->setComment($_POST['comments']); $um->setClass($_POST['feature']); $um->setUserStatus($_POST['supplemental']); $um->processUpload($_FILES['uploadfile']['tmp_name']); // where there any errors back from the image processing? // if so, JUppy needs to know... if ($um->error != "") { $xml['status'] = $um->error; } else { // so far so good... can we commit the submission? $rc = $um->commit(); if ($rc == "") { //clear user profile $ab = floor($USER->user_id / 10000); $smarty = new GeographPage(); $smarty->clear_cache(null, "user{$ab}|{$USER->user_id}"); $xml['status'] = "OK"; } else { $xml['status'] = $rc; } } returnXML(); }
/** * general purpose internal method for creating resized images - accepts * a variety of options. Use this to build specific methods for public * consumption * * maxw : maximum width of image (default '100') * maxh : maximum height of image (default '100') * bestfit : show entire image inside max width/height. If false * then the image is cropped to match the aspect ratio of * of the target area first (default 'true') * attribname : attribute name of img tag which holds url (default 'src') * bevel : give image a raised edge (default true) * unsharp : do an unsharp mask on the image * pano : do not crop, even if w:h > 2:1 (default false) * * returns an association array containing 'html' element, which contains * a fragment to load the image, and 'path' containg relative url to image */ function _getResized($params) { global $memcache, $CONF, $MESSAGES; $mkey = "{$this->gridimage_id}:" . md5(serialize($params)); //fails quickly if not using memcached! $result =& $memcache->name_get('ir', $mkey); if ($result && $result['url'] != '/photos/error.jpg') { return $result; } //unpack known params and set defaults $maxw = isset($params['maxw']) ? $params['maxw'] : 100; $maxh = isset($params['maxh']) ? $params['maxh'] : 100; $attribname = isset($params['attribname']) ? $params['attribname'] : 'src'; $bestfit = isset($params['bestfit']) ? $params['bestfit'] : true; $bevel = isset($params['bevel']) ? $params['bevel'] : true; $unsharp = isset($params['unsharp']) ? $params['unsharp'] : true; $pano = isset($params['pano']) ? $params['pano'] : false; $source = isset($params['source']) ? $params['source'] : ''; global $CONF; //establish whether we have a cached thumbnail $ab = sprintf("%02d", floor($this->gridimage_id % 1000000 / 10000)); $cd = sprintf("%02d", floor($this->gridimage_id % 10000 / 100)); $abcdef = sprintf("%06d", $this->gridimage_id); $hash = $this->_getAntiLeechHash(); $base = $_SERVER['DOCUMENT_ROOT'] . '/photos'; if ($this->gridimage_id < 1000000) { $thumbpath = "/photos/{$ab}/{$cd}/{$abcdef}_{$hash}_{$maxw}x{$maxh}.jpg"; } else { $yz = sprintf("%02d", floor($this->gridimage_id / 1000000)); $thumbpath = "/geophotos/{$yz}/{$ab}/{$cd}/{$abcdef}_{$hash}_{$maxw}x{$maxh}.jpg"; } if (!empty($params['urlonly']) && $params['urlonly'] !== 2 && file_exists($_SERVER['DOCUMENT_ROOT'] . $thumbpath)) { $return = array(); $return['url'] = $thumbpath; if (!empty($CONF['enable_cluster'])) { $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}"); } else { $return['server'] = "http://" . $CONF['CONTENT_HOST']; } return $return; } $mkey = "{$this->gridimage_id}:{$maxw}x{$maxh}"; //fails quickly if not using memcached! $size =& $memcache->name_get('is', $mkey); if ($size) { $return = array(); $return['url'] = $thumbpath; $by = $MESSAGES['class_gridimage']['by']; $title = $this->grid_reference . ' : ' . htmlentities2($this->title) . $by . htmlentities2($this->realname); if (!empty($CONF['enable_cluster'])) { $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}"); } else { $return['server'] = "http://" . $CONF['CONTENT_HOST']; } $thumbpath = $return['server'] . $thumbpath; if (isset($CONF['curtail_level']) && $CONF['curtail_level'] > 1 && empty($GLOBALS['USER']->user_id) && isset($GLOBALS['smarty'])) { $thumbpath = cachize_url($thumbpath); } $html = "<img alt=\"{$title}\" {$attribname}=\"{$thumbpath}\" {$size[3]} />"; $return['html'] = $html; return $return; } if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $thumbpath)) { if ($source == 'original') { $fullpath = $this->_getOriginalpath(); } else { //get path to fullsize image (will try to fetch it from fetch_on_demand) $fullpath = $this->_getFullpath(); } if ($pano && $fullpath != '/photos/error.jpg' && file_exists($_SERVER['DOCUMENT_ROOT'] . $fullpath)) { require_once "geograph/uploadmanager.class.php"; $uploadmanager = new UploadManager(); list($owidth, $oheight, $otype, $oattr) = getimagesize($_SERVER['DOCUMENT_ROOT'] . $fullpath); list($destwidth, $destheight, $destdim, $changedim) = $uploadmanager->_new_size($owidth, $oheight, $maxw); $maxw = $destdim; $maxh = $destdim; $bestfit = true; } if ($fullpath != '/photos/error.jpg' && file_exists($_SERVER['DOCUMENT_ROOT'] . $fullpath)) { if (strlen($CONF['imagemagick_path'])) { if (($info = getimagesize($_SERVER['DOCUMENT_ROOT'] . $fullpath)) === FALSE) { //couldn't read image! $thumbpath = "/photos/error.jpg"; } else { list($width, $height, $type, $attr) = $info; if ($width > $maxw || $height > $maxh || !$bestfit) { $unsharpen = $unsharp ? "-unsharp 0x1+0.8+0.1" : ""; $raised = $bevel ? "-raise 2x2" : ""; $operation = $maxw + $maxh < 400 ? 'thumbnail' : 'resize'; $aspect_src = $width / $height; $aspect_dest = $maxw / $maxh; if (!$pano && $bestfit && $aspect_src > 2 && $aspect_dest < 2) { $bestfit = false; $maxh = round($maxw / 2); $aspect_dest = 2; } if ($bestfit) { $cmd = sprintf("\"%sconvert\" -{$operation} %ldx%ld {$unsharpen} {$raised} -quality 87 jpg:%s jpg:%s", $CONF['imagemagick_path'], $maxw, $maxh, $_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath); passthru($cmd); } else { if ($aspect_src > $aspect_dest) { //src image is relatively wider - we'll trim the sides $optimum_width = round($height * $aspect_dest); $offset = round(($width - $optimum_width) / 2); $crop = "-crop {$optimum_width}x{$height}+{$offset}+0"; } else { //src image is relatively taller - we'll trim the top/bottom $optimum_height = round($width / $aspect_dest); $offset = round(($height - $optimum_height) / 2); $crop = "-crop {$width}x{$optimum_height}+0+{$offset}"; } $cmd = sprintf("\"%sconvert\" {$crop} -quality 87 jpg:%s jpg:%s", $CONF['imagemagick_path'], $_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath); passthru($cmd); //now resize // FIXME: one step! $cmd = sprintf("\"%smogrify\" -{$operation} %ldx%ld {$unsharpen} {$raised} -quality 87 jpg:%s", $CONF['imagemagick_path'], $maxw, $maxh, $_SERVER['DOCUMENT_ROOT'] . $thumbpath); passthru($cmd); } } else { //requested thumb is larger than original - stick with original copy($_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath); } } } else { // FIXME not the same as above //generate resized image $fullimg = @imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] . $fullpath); if ($fullimg) { $srcw = imagesx($fullimg); $srch = imagesy($fullimg); if ($srcw > $maxw || $srch > $maxh) { //figure out size of image we'll keep if ($srcw > $srch) { //landscape $destw = $maxw; $desth = round($destw * $srch / $srcw); } else { //portrait $desth = $maxh; $destw = round($desth * $srcw / $srch); } $resized = imagecreatetruecolor($destw, $desth); imagecopyresampled($resized, $fullimg, 0, 0, 0, 0, $destw, $desth, $srcw, $srch); if ($unsharp) { require_once 'geograph/image.inc.php'; UnsharpMask($resized, 100, 0.5, 3); } imagedestroy($fullimg); //save the thumbnail imagejpeg($resized, $_SERVER['DOCUMENT_ROOT'] . $thumbpath, 85); imagedestroy($resized); } elseif ($srcw == 0 && $srch == 0) { //couldn't read image! $thumbpath = "/photos/error.jpg"; imagedestroy($fullimg); } else { //requested thumb is larger than original - stick with original copy($_SERVER['DOCUMENT_ROOT'] . $fullpath, $_SERVER['DOCUMENT_ROOT'] . $thumbpath); } } else { //couldn't load full jpeg $thumbpath = "/photos/error.jpg"; } } } else { //no original image! - return link to error image $thumbpath = "/photos/error.jpg"; } } $return = array(); $return['url'] = $thumbpath; if ($thumbpath == '/photos/error.jpg') { $html = "<img {$attribname}=\"{$thumbpath}\" width=\"{$maxw}\" height=\"{$maxh}\" />"; } else { $by = $MESSAGES['class_gridimage']['by']; $title = $this->grid_reference . ' : ' . htmlentities2($this->title) . $by . htmlentities2($this->realname); $size = getimagesize($_SERVER['DOCUMENT_ROOT'] . $thumbpath); if (!empty($CONF['enable_cluster'])) { $return['server'] = str_replace('0', $this->gridimage_id % $CONF['enable_cluster'], "http://{$CONF['STATIC_HOST']}"); } else { $return['server'] = "http://" . $CONF['CONTENT_HOST']; } $thumbpath = $return['server'] . $thumbpath; if (isset($CONF['curtail_level']) && $CONF['curtail_level'] > 1 && empty($GLOBALS['USER']->user_id) && isset($GLOBALS['smarty'])) { $thumbpath = cachize_url($thumbpath); } $html = "<img alt=\"{$title}\" {$attribname}=\"{$thumbpath}\" {$size[3]} />"; //fails quickly if not using memcached! $memcache->name_set('is', $mkey, $size, $memcache->compress, $memcache->period_med); } $return['html'] = $html; return $return; }