How to read content of uploaded file without of saving

Hello

I want to upload file, read the content, output it, but i don’t want to save this file on server




public function actionUpload()

{

    $model=new UploadForm;

    if(isset($_POST['UploadForm']))

    {

        $model->attributes=$_POST['UploadForm'];            

	if($model->validate()) {

            $model->file=CUploadedFile::getInstance($model,'file');

            //how to output content of uploaded file?

	}

    }

}



Is it right way?




$file=CUploadedFile::getInstance($model,'file');

$content=file_get_contents($file->tempName);

The server can’t get the file’s contents, as the file resides on the client. You could simply remove the file after uploading it and getting its contents:




$uploadedFile = CUploadedFile::getInstance($model, 'file');

$newFilePath = "tmp/{$uploadedFile->name}";

$uploadSuccess = $uploadedFile->saveAs($newFilePath);

if (!$uploadSuccess) {

   throw new CHttpException('Error uploading file.');  

}

$content=file_get_contents($newFilePath);

unlink($newFilePath);



:mellow: