茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    yii結(jié)合ckeditor實(shí)現(xiàn)圖片上傳功能
    來(lái)源:易賢網(wǎng) 閱讀:1009 次 日期:2014-10-08 13:16:02
    溫馨提示:易賢網(wǎng)小編為您整理了“yii結(jié)合ckeditor實(shí)現(xiàn)圖片上傳功能”,方便廣大網(wǎng)友查閱!

    這幾天做的一個(gè)項(xiàng)目中需要在所見(jiàn)即所得編輯器中實(shí)現(xiàn)圖片上傳的功能,我因?yàn)楸容^喜歡ckeditor的界面而選擇了它。雖然有跟ckeditor配合良好的ckfinder,不過(guò)這個(gè)東東的功能太復(fù)雜,簡(jiǎn)單看了下ckedtior的文檔,發(fā)現(xiàn)這個(gè)功能還是可以自己實(shí)現(xiàn)而不用借助ckfinder的。

    下面代碼雖然基于yii framework的,但是用其他框架或者語(yǔ)言思路卻是完全一樣的,有需要的童鞋可以參考一下。

    首先要讓ckeditor出現(xiàn)圖片上傳的功能,需要配置編輯器的filebrowserimageuploadurl屬性:

    代碼如下:

    ckeditor.replace( 'editor1',

    {

    filebrowseruploadurl : '/uploader/upload.php',

    filebrowserimageuploadurl : '/uploader/upload.php?type=images'

    });

    然后在對(duì)應(yīng)的url上實(shí)現(xiàn)圖片上傳的功能,并向ckeditor返回特定格式的html代碼,ckeditor就能正常預(yù)覽并插入圖片了。

    下面只截取控制器的部分代碼,controller部分我是這樣實(shí)現(xiàn)的:

    代碼如下:

    /**

    * 保存上傳的圖片

    *

    * @return string javascript code

    * @author lfyzjck

    **/

    public function actionimg($type, $ckeditor, $ckeditorfuncnum, $langcode = 'zh-cn')

    {

    if(empty($ckeditorfuncnum) || $type != 'images'){

    $this->mkhtml($ckeditorfuncnum,'','錯(cuò)誤的函數(shù)調(diào)用');

    }

    if(isset($_files['upload'])){

    //獲取關(guān)于圖片上傳配置

    $options = options::model()->findbypk(1);

    $form = new uploadform('image',$options);

    $form->upload = cuploadedfile::getinstancebyname('upload');

    if($form->validate()){

    //文件名:時(shí)間+源文件名

    $target_filename = date('ymd-hm',time()).$form->upload->getname();

    $path = yii::app()->basepath.'/../uploads/'.$target_filename; //圖片保存路徑

    $form->upload->saveas($path);

    $this->mkhtml($ckeditorfuncnum,yii::app()->baseurl.'/uploads/'.$target_filename, 上傳成功);

    }

    else{

    $this->mkhtml($ckeditorfuncnum,'',$form->geterror('upload'));

    }

    }

    }

    /**

    * 返回ckeditor的提示信息

    *

    * @return void

    * @author lfyzjck

    **/

    private function mkhtml($fn, $fileurl, $message)

    {

    $str = '';

    exit($str);

    }

    需要特別說(shuō)明的mkhtml函數(shù),他會(huì)調(diào)用ckeditor的函數(shù)產(chǎn)生提示信息。上傳成功的時(shí)候?qū)D片鏈接返回,ckeditor會(huì)根據(jù)url生成圖片預(yù)覽。

    然后是uploadform的代碼,這里會(huì)驗(yàn)證圖片的格式和大小是否符合要求。

    代碼如下:

    class uploadform extends cformmodel

    {

    public $upload;

    private $options;

    private $type;

    public function __construct($type, $options){

    $this->options = $options;

    $this->type = $type;

    }

    /**

    * declares the validation rules.

    * the rules state that username and password are required,

    * and password needs to be authenticated.

    */

    public function rules()

    {

    return array(

    array('upload', 'file',

    'types' => $this->options->getattribute(allow_.$this->type._type),

    'maxsize' => 1024 * (int)$this->options->getattribute(allow_.$this->type._maxsize),

    'toolarge'=>'文件大小超過(guò)限制',

    ),

    );

    }

    }

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:yii結(jié)合ckeditor實(shí)現(xiàn)圖片上傳功能
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)