本文整理汇总了PHP中UploadHandler::setNewName方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadHandler::setNewName方法的具体用法?PHP UploadHandler::setNewName怎么用?PHP UploadHandler::setNewName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadHandler
的用法示例。
在下文中一共展示了UploadHandler::setNewName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload_image
function upload_image($image_path = '',$filed='face',$small_width=80,$small_height=80)
{
if($image_path == '') {
$image_path = IMAGE_PATH.'/'.$filed.'/';
}
$date=date("Y-m-d");
if(empty($_FILES) or empty($filed)) {
return array('error'=>__('上传图片出错!请检查您的服务器环境!'));
}
if ($_FILES[$filed]['name']=='') {
return array('error'=>__('您没有选择需要上传的图片!'));
}
$default_type=array('jpg','pic','png','jpeg','bmp','gif'); $imgary=explode('.',$_FILES[$filed]['name']);
if(!in_array(strtolower($imgary[count($imgary)-1]),$default_type)){
return array('error'=>'不支持的图片格式 ['.$imgary[count($imgary)-1].'] !');
}
require_once LIB_PATH . 'upload.han.php';
$upload_handler = new UploadHandler($_FILES, $image_path, $filed , true);
if(is_dir($image_path.$date)==false or is_dir($image_path.SMALL_PIC_PREFIX.$date)==false)
{
require_once LIB_PATH. 'io.han.php';
IoHandler::MakeDir($image_path.$date);
IoHandler::MakeDir($image_path.SMALL_PIC_PREFIX.$date);
}
$upload_handler->setMaxSize(1024); $name = $date.'/'.substr(md5(microtime()).'.'.strtolower(end(explode('.', $_FILES[$filed]['name']))),-15);
$size = $_FILES[$field]['size'];
$photo['name']=$name;
$photo['size']=$size;
$upload_handler->setNewName($name);
$result = $upload_handler->doUpload();
if (false == $result)
{
return array('error'=>$upload_handler->getError());
}
$result = resize_image($image_path.$name,
$image_path.SMALL_PIC_PREFIX.$name,
$small_width,
$small_height,
false);
return $name;
}
示例2: UploadImage
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);
}
示例3: UploadImage
function UploadImage()
{
LogMessage("UploadImage");
$this->GotoLogin();
$imgId = $this->ImgLogic->AddNewImage();
$this->Logger->Write($imgId);
if (!$imgId || $imgId <= 0) {
echo "0";
return;
}
$uid = $this->User['uid'];
$this->Logger->Write($uid);
$this->User = $this->UserLogic->GetUser($uid);
$IoHandler = new IoHandler();
$item = $this->Post['item'] ? $this->Post['item'] : $this->Get['item'];
$itemId = $this->Post['itemId'] ? $this->Post['itemId'] : $this->Get['itemId'];
$imgtype = $this->Post['imgtype'] ? $this->Post['imgtype'] : $this->Get['imgtype'];
$name = $_FILES['Filedata']['name'];
$this->Logger->Write($name);
$id = $imgId;
$subfolder = 'topic';
if ($item != '') {
$subfolder = $item;
} else {
}
$rpath = 'images/' . $subfolder . '/' . 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';
$image_file_tp = $rpath . $id . '_tp.jpg';
$image_file_avt = '';
$pic_field = 'Filedata';
$UploadHandler = new UploadHandler($_FILES, $image_path, $pic_field, true, false);
$UploadHandler->setMaxSize(3072);
$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->ImgLogic->DeleteImage($imgId);
$error = $UploadHandler->getError();
$result = array();
$result['status'] = "failed";
$result['message'] = urlencode($error);
echo urldecode(json_encode($result));
exit;
}
}
$image_type = $info['type'];
list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_file);
//this file used for topic list
$Images = new ImagesHandler('Filedata');
$Images->item_type = $item;
$w = 120;
$h = 120;
if ($item == 'event') {
$h = 105;
}
//if($image_width>1500){
// LogMessage('resize to 1500 size');
// resizeimage($image_file, $image_file_tp,1500,0,true);
// LogMessage('resize to 1500 size done');
// $image_file=$image_file_tp;
// list($image_width,$image_height,$image_type,$image_attr) = getimagesize($image_file_tp);
//}
LogMessage("uploaed completed,going to resize image");
if ($image_width == $image_height) {
LogMessage("Width is equal to height");
$resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_width, $image_height, $w, $h, 'jpg');
} else {
if ($image_height > $image_width) {
LogMessage("Width is less than height");
$resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_width, $image_width, $w, $h, 'jpg');
} else {
if ($image_height < $image_width) {
LogMessage("Width is larger than height");
$resize = $Images->thumb($image_file, false, 1, $rpath . $id, 0, 0, $image_height, $image_height, $w, $h, 'jpg');
}
}
}
if (!$resize) {
$result['status'] = "failed";
$result['message'] = "图片上传失败";
$this->ImgLogic->DeleteImage($imgId);
$IoHandler->DeleteFile($image_file);
echo json_encode($result);
exit;
}
if ($this->CallType != 'open') {
//reduce the photo quality, but keep photo original width and height
resizeimage($image_file, $image_file_t, 1024, 0, true);
} else {
copy($image_file, $image_file_t);
}
if ($image_file_avt && $image_file_avt != '') {
//.........这里部分代码省略.........