本文整理匯總了PHP中think\Upload::getErrorMsg方法的典型用法代碼示例。如果您正苦於以下問題:PHP Upload::getErrorMsg方法的具體用法?PHP Upload::getErrorMsg怎麽用?PHP Upload::getErrorMsg使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類think\Upload
的用法示例。
在下文中一共展示了Upload::getErrorMsg方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: uploadImg
public function uploadImg()
{
$upload = new Upload(C('UPLOAD_CONFIG'));
// 實例化上傳類
//頭像目錄地址
$path = './Avatar/';
if (!$upload->upload()) {
// 上傳錯誤提示錯誤信息
$this->ajaxReturn(array('status' => 0, 'info' => $upload->getErrorMsg()));
} else {
// 上傳成功 獲取上傳文件信息
$temp_size = getimagesize($path . 'temp.jpg');
if ($temp_size[0] < 150 || $temp_size[1] < 150) {
//判斷寬和高是否符合頭像要求
$this->ajaxReturn(array('status' => 0, 'info' => '圖片寬或高不得小於100px!'));
}
$this->ajaxReturn(array('status' => 1, 'path' => __ROOT__ . '/Avatar/' . 'temp.jpg'));
}
}
示例2: do_edit
/**
* 處理修改
*/
public function do_edit()
{
C('TOKEN_ON', false);
// dump($_POST);
// exit;
$file = $_FILES;
$file = $file['advert_image'];
$file = $file['name'];
// dump($file);
// exit;
if (empty($file)) {
$m = D('Advert');
if (!$m->create()) {
$this->error($m->geterror());
}
$data['id'] = I('post.id');
$data['advert_nav'] = I('post.advert_nav');
$data['advert_name'] = I('post.advert_name');
$data['advert_remark'] = I('post.advert_remark');
$data['advert_url'] = I('post.advert_url');
$data['advert_sort'] = I('post.advert_sort');
$data['advert_show'] = I('post.advert_show');
$count = $m->save($data);
//修改表單用save函數
if ($count > 0) {
$this->success('修改成功!');
} else {
$this->error('修改失敗!');
}
} else {
$id = I('post.id');
$m = M('Advert');
$arr = $m->find($id);
// dump($arr);
// exit;
if (!$arr['advert_image'] == null) {
//刪除本地圖片附件 unlink('圖片url')
unlink('./Uploads' . $arr["advert_image"]);
}
$upload = new \Think\Upload();
// 實例化上傳類
$upload->maxSize = 3145728;
// 設置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');
// 設置附件上傳類型
$upload->savePath = './Uploads/';
// 設置附件上傳根目錄
$upload->savePath = '/Images/';
// 網站主欄目圖片 設置附件上傳(子)目錄
$upload->autoSub = true;
$upload->subName = array('date', 'Ymd');
$upload->saveName = array('uniqid', '');
//設置上傳文件規則
$info = $upload->upload();
//設置需要生成縮略圖,僅對圖像文件有效
//$upload->thumb = true;
//設置需要生成縮略圖的文件後綴
//$upload->thumbPrefix = 'm_,s_'; //生產2張縮略圖
//設置縮略圖最大寬度
//$upload->thumbMaxWidth = '400,100';
//設置縮略圖最大高度
//$upload->thumbMaxHeight = '400,100';
//$upload->thumbRemoveOrigin = true;//刪除原圖
if (!$info) {
//捕獲上傳異常
$this->error($upload->getErrorMsg());
} else {
//取得成功上傳的文件信息
//給m_縮略圖添加水印, Image::water('原文件名','水印圖片地址')
//Image::water($uploadList[0]['savepath'] . 'm_' . $uploadList[0]['savename'], APP_PATH.'Tpl/Public/Images/logo.png');
//dump($uploadList[0]);
//exit;
foreach ($info as $file) {
$image = $file['savepath'] . $file['savename'];
$size = $file['size'];
}
}
// dump($size);
// exit;
$m = M('Advert');
$data['id'] = I('post.id');
$data['advert_nav'] = I('post.advert_nav');
$data['advert_name'] = I('post.advert_name');
$data['advert_remark'] = I('post.advert_remark');
$data['advert_url'] = I('post.advert_url');
$data['advert_show'] = I('post.advert_show');
$data['advert_sort'] = I('post.advert_sort');
//$date['advert_time']=time();
$data['advert_image'] = $image;
$data['advert_size'] = $size;
$count = $m->save($data);
//修改表單用save函數
// dump($count);
// exit;
if ($count > 0) {
$this->success('修改成功!');
} else {
//.........這裏部分代碼省略.........