public function getUrl()
{
//return Yii::getAlias('@web') . '/' . $this->getFilePath(false);
// return Yii::$app->response->sendFile(Site::UPLOADS_DOMAIN . '/' . $this->getFilePath(false), $this->original_name);
return Site::UPLOADS_DOMAIN . '/' . $this->getFilePath(false);
//return \yii\helpers\Url::home(true) . '/' . $this->getFilePath(false);
}
public function getFileName($withExtension = false)
{
$ext = $withExtension ? '.' . $this->getFileExtension() : '';
// return $this->original_name . $ext;
return $this->hash . $ext;
}
if ($file) {
$obj = $storage->download($file);
if (!is_null($obj)) {
$meta = $storage->getInfoFile($file);
ob_get_level() && ob_end_clean();
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
header('Content-Type: application/force-download');
header('Content-Description: inline; File Transfer');
header('Content-Transfer-Encoding: binary');
if (array_key_exists('name', $meta) & array_key_exists('size', $meta)) {
header('Content-Disposition: attachment; filename="' . $meta['name'] . '";', false);
header('Content-Length: ' . $meta['size']);
}
$speed = 1024 * $limit;
if ($speed > 0) {
$sleep = 1;
} else {
$speed = 8 * 1024;
$sleep = 0;
}
while (!$obj->eof()) {
$buf = $obj->fread($speed);
print($buf);
if ($sleep) {
sleep(1);
}
flush();
}
exit;
}
$message = $message->withHeader('fOO', 'baz');
так как мне передать это имя пользователюИз всего диалога в комментариях должен быть вывод:
header('Content-Disposition: attachment; filename="' . $meta['name'] . '";', false);
, где $meta['name'] - имя под которым должно сохраниться у пользователя. public function fields()
{
$fields = parent::fields();
...
$fields['images'] = function (Material $model) {
return UploadBind::get($model, 'images', ['active' => 1]);
};
...
return $fields;
}
public static function get($model, $attrs = null, $conditions = [], $asQuery = 0, $addUploads = 1)
{
$defaultConditions = [
'model_name' => $model::className(),
'model_id' => $model->getAttribute('id'),
];
if ($attrs)
$defaultConditions['model_attr'] = $attrs;
$conditions = array_merge($defaultConditions, $conditions);
$q = UploadBind::find()->where($conditions)->orderBy('sort');
if ($asQuery) {
return $q;
}
/** @var UploadBind[] $binds */
$binds = $q->all();
if ($addUploads) {
$uploadsIds = ArrayHelper::getColumn($binds, 'upload_id');
//$uploads = Upload::findAll(['id' => $uploadsIds]);
$uploads = Upload::find()->where(['id' => $uploadsIds])->all();
$uploadsMap = ArrayHelper::map($uploads, 'id', function ($x) {
return $x;
});
foreach ($binds as $bind) {
$bind->upload = $uploadsMap[$bind->upload_id];
}
}
return $binds;
}