<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yzxh24
 * Date: 11-10-8
 * Time: 下午6:12
 * To change this template use File | Settings | File Templates.
 */
class UploadAction extends BaseAction
{
    public function run()
    {
        $id = Yii::app()->request->getQuery('id');
        $soft = SoftContent::model()->findByPk($id);
        if (empty($soft))
        {
            echo '不存在的软件';
            Yii::app()->end();
        }

        $softPcontent = new SoftPcontent();
        $softPcontent->Filedata = CUploadedFile::getInstance($softPcontent, 'Filedata');
        
        $fileExt = CFileHelper::getExtension($softPcontent->Filedata->getName());
        $newFileName = Helper::guid() . '.' . $fileExt;
        $fileName = $softPcontent->Filedata->getName();


        $softPcontent->cid = $soft->id;
        $softPcontent->name = $fileName;
        $softPcontent->filename = $newFileName;
        $softPcontent->date = date('Y-m-d');
        $softPcontent->size = $softPcontent->Filedata->getSize();
        $softPcontent->filetype = getFileType($fileExt);

        $savePath = Front::getSoftBaseSavePath($softPcontent->date);
        if (false === $savePath)
        {
            echo '文件保存目录不可写';
            Yii::app()->end();
        }
        $saveFile = $savePath . $newFileName;
        $softPcontent->Filedata->saveAs($saveFile);
        $softPcontent->save();

        echo 'FILEID:'.$softPcontent->id;
        Yii::app()->end();
    }
}