Yii2:Unknown Method中的错误下载文件PDF

时间:2018-04-11 04:31:13

标签: file pdf download yii2 yii2-advanced-app

我想从 private void addGeoTag(File file){ ExifInterface exif; double latitude = 17.4436; double longitude = 78.4458; try { System.out.println("file is--->"+file.toString()); exif = new ExifInterface(file.toString()); int num1Lat = (int)Math.floor(latitude); int num2Lat = (int)Math.floor((latitude - num1Lat) * 60); double num3Lat = (latitude - ((double)num1Lat+((double)num2Lat/60))) * 3600000; int num1Lon = (int)Math.floor(longitude); int num2Lon = (int)Math.floor((longitude - num1Lon) * 60); double num3Lon = (longitude - ((double)num1Lon+((double)num2Lon/60))) * 3600000; exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, num1Lat+"/1,"+num2Lat+"/1,"+num3Lat+"/1000"); exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, num1Lon+"/1,"+num2Lon+"/1,"+num3Lon+"/1000"); if (latitude > 0) { exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N"); } else { exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S"); } if (longitude > 0) { exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E"); } else { exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W"); } exif.saveAttributes(); } catch (IOException e) { Log.e("PictureActivity", e.getLocalizedMessage()); } } 下载文件PDF。我在控制器中有一个错误(可能):

  

调用未知方法:import sys non_bmp_map = dict.fromkeys(range(0x10000, sys.maxunicode + 1), 0xfffd) text = '\u3010\U0001f469\U0001f3fb\u200d' text.translate(non_bmp_map)#'【��\u200d'

这是我的源代码:

BukuController.php

frontend/web/uploads

这是视图中的功能,frontend\controllers\BukuController::findModel()

public function actionDownload($id)
{
    $model = $this->findModel($id);
    $file ='../frontend/uploads/'.$model->file_buku;

    if(file_exists($file))
    {
        return Yii::$app->response->sendFile($file);
        exit;
    }
}

(已解决)

2 个答案:

答案 0 :(得分:0)

作为错误状态,您在名为findModel的BukuController方法中丢失了。 此方法应在DB中搜索模型。 像这样:

protected function findModel($id)
{
    if (!is_null($model = Buku::findOne($id))) {
        return $model;
    }
    throw new NotFoundHttpException('The requested page does not exist.');
}

当然,如果您的模型不是Buku,则需要相对更改它,并将其导入控制器文件的顶部:

use app\models\Buku; // Basic application.
use common\models\Buku; // Advanced application when models store in common folder.
use frontend\models\Buku; // Advanced application when models store in frontend folder.

答案 1 :(得分:0)

$file变量更改为此。

<强> $file =Yii::$app->getBasePath().'/web/uploads/'.$model->file_buku;