Giter VIP home page Giter VIP logo

plupload's Introduction

 /**
 * @return array list of actions.
 */
public function actions()
{
    return array(
        'upload' => array(
            'class' => '\yii-ext\plupload\Action',
            'completeCallback' => function ($fileFullName, $fileSelfName) {
        $fileModel = new UserFileModel();
        $fileModel->userId = Yii::app()->user->id;
        $fileModel->name = $fileSelfName;
        $fileModel->file = $fileFullName;
        if (!$fileModel->save()) {
            throw new CHttpException(500, CVarDumper::dumpAsString($fileModel->getErrors()));
        }
        $response = array(
            'downloadUrl' => Yii::app()->createUrl('downloadfile', array('id' => $fileModel->id)),
            'deleteUrl' => Yii::app()->createUrl('deletefile', array('id' => $fileModel->id)),
        );
        return $response;
    }
        )
    );
}
Upload CV Files:
widget('FileUploader', array( 'id' => 'filelist', 'uploadUrl' => array('upload'), 'files' => $userModel->files, 'maxFileCount' => 3, 'clientOptions' => array( 'filters' => array( 'mime_types' => array( array( 'title' => 'Documents', 'extensions' => implode(',', Yii::app()->params['allowedUserFileTypes']), ) ), 'max_file_size' => '2mb', 'prevent_duplicates' => true, ), ), )); ?>
**
 * Allow downloading of the user file specified by its id.
 * @param integer $id user file id.
 * @throws CHttpException on failure.
 */
public function actionDownloadfile($id)
{
    $userFileModel = $this->loadUserFileModel($id);
    Yii::app()->getRequest()->sendFile($userFileModel->getFileSelfName(), $userFileModel->getFileContent());
}

/**
 * Deletes user file specified by its id.
 * @param integer $id user file id.
 * @throws CHttpException on failure.
 */
public function actionDeletefile($id)
{
    $userFileModel = $this->loadUserFileModel($id);
    $userFileModel->delete();
    if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
        $this->redirect(array('resume'));
    } else {
        Yii::app()->end();
    }
}

/**
 * Finds the user file model specified by id.
 * Checks if model belongs to the current user.
 * @param integer $id user file id.
 * @return UserFileModel|\zfort\db\ar\behaviors\File user file model instance.
 * @throws CHttpException on failure.
 */
protected function loadUserFileModel($id)
{
    /* @var UserFileModel|zfort\db\ar\behaviors\File $userFileModel */
    /* @var WebUser $webUser */
    $webUser = Yii::app()->getComponent('user');
    $userFileModel = UserFileModel::model()->findByPk($id);
    if (!is_object($userFileModel) || $userFileModel->userId != $webUser->getId()) {
        throw new CHttpException(404, 'Unable to find requested file');
    }
    return $userFileModel;
}

plupload's People

Contributors

dmitry-semenov avatar

Watchers

James Cloos avatar Valeriy Zavolodko avatar

Forkers

hizamomar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.