webyjh 2011-12-30 21:10:09 2733次浏览 5条回复 0 0 0

生成缩略图的扩展位置放置正确了,却提示找不到扩展 include(CThumb.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

  • 回复于 2011-12-30 21:15 举报

    把代码帖出来看看!

  • 回复于 2011-12-31 07:04 举报
    <table>
    <tr><td style='text-align:right;width:100px;'> <?php echo $form->labelEx($model,'front_img'); ?></td>
    <td>
    <?php echo $form->FileField($model, 'front_img',array('style'=>'width:300px;')); ?>
    </td>
    </tr>
    </table>
    

    控制器中的代码

    public function actionCreate()
    {
        $model=new News;
    
        // Uncomment the following line if AJAX validation is needed
        $this->performAjaxValidation($model);
    
        if(isset($_POST['News']))
        {
            $model->attributes=$_POST['News'];
            $model->front_img=CUploadedFile::getInstance($model,'front_img');
            if($model->save())
            {                 
                //按时间生成新文件名
                $newName=date('YmdHis').'_'.rand(1,9).'.'.$model->front_img->extensionName;
                //设定上传目录
                $path=yii::app()->basePath.'/../uploads/images/'.$newName;
                //上传图片
                $model->front_img->saveAs($path);
                //利用扩展生成缩略图
                $im = null;
                $imagetype = strtolower($model->front_img->extensionName);
                if($imagetype == 'gif')
                    $im = imagecreatefromgif($path);
                else if ($imagetype == 'jpg')
                    $im = imagecreatefromjpeg($path);
                else if ($imagetype == 'png')
                    $im = imagecreatefrompng($path);
                CThumb::resizeImage($im,100, 100,'e:\\kanbox\\phpnow\\htdocs\\cnsstc' .             $model->front_img->extensionName, $model->front_img->extensionName );
                    
                // redirect to success page
                $this->redirect(array('view','id'=>$model->id));                
            }        
        }
        $this->render('create',array(
                'model'=>$model,
        ));
    }
    
  • 回复于 2011-12-31 08:43 举报

    修改protected/config/main.php

    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'application.extensions.*',    //这里要引入extensions目录。
    ),
    
  • 回复于 2011-12-31 08:58 举报

    晕啊,我把components看成extensions,还以为引入了,嘿嘿,
    还是舰长V5

  • 回复于 2012-04-18 14:22 举报

    谢谢,问题解决了,记得引入文件阿

您需要登录后才可以回复。登录 | 立即注册