Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Yii How Download Uploaded Files?

$
0
0
Hello, i have some problem. I need download my (uploaded file when i create new TASK ) :

My Task Controller :
public function actionCreate() {
        $model = new Task;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

        if (isset($_POST['Task'])) {
            $model->attributes = $_POST['Task'];

            $uploadedFile = CUploadedFile::getInstance($model, 'image');
            $fileName = time() . '_' . $uploadedFile->name;  // $timestamp + file name

            if (!is_dir(Yii::app()->basePath . '/upload/' . $model->project->id . '/' . $model->id)) {
                mkdir(Yii::app()->basePath . '/upload/' . $model->project->id);
            }
           
            if ($model->save()) {
                
                mkdir(Yii::app()->basePath . '/upload/' . $model->project->id . '/' . $model->id);
                $path = Yii::app()->basePath . '/upload/' . $model->project->id . '/' . $model->id .'/'.  $fileName;
                if ($uploadedFile->saveAs($path)) {
                    $modelFile = new Files;
                    $modelFile->task_id = $model->id;   
                    $modelFile->path = $path;
                    $modelFile->save();
                }
            }


This function create new task and upload file to : basePath/upload/project_id/task_id/file.png

How i can render this file.png? and how i can download it?

Path "basePath/upload/project_id/task_id/file.png" has saved in "files" table .

Viewing all articles
Browse latest Browse all 18717

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>