本文整理汇总了PHP中FileHelper::forceDownload方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::forceDownload方法的具体用法?PHP FileHelper::forceDownload怎么用?PHP FileHelper::forceDownload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelper
的用法示例。
在下文中一共展示了FileHelper::forceDownload方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forceDownload
public static function forceDownload($model, $name_field)
{
$src = '';
$className = get_class($model);
if ($className == 'ProListingUploadCea') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$src = "upload/listing/" . $model->listing_id . "/cea/" . $fileName;
} elseif ($className == 'ProTransactionsPropertyDocument') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$src = "upload/transactions/property_document/" . $model->transactions_id . "/" . $fileName;
} elseif ($className == 'ProUploadDocument') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$src = "upload/document/" . $model->user_id . "/" . $fileName;
} else {
throw new Exception('Invalid request.');
}
$fileHelper = new FileHelper();
$fileHelper->forceDownload($src);
}
示例2: forceDownload
public static function forceDownload($model, $name_field, $folder)
{
try {
$className = get_class($model);
if ($className == 'PrecProductFamily') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$checkSpace = explode(' ', $model->{$name_field});
if (count($checkSpace) > 1) {
$fileName = rawurlencode($fileName);
}
$src = "upload/products/" . $model->id . "/{$folder}/" . $fileName;
} elseif ($className == 'PrecWhitepaper') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$checkSpace = explode(' ', $model->{$name_field});
if (count($checkSpace) > 1) {
$fileName = rawurlencode($fileName);
}
$src = "upload/{$folder}/" . $model->id . "/" . $fileName;
} elseif ($className == 'PrecPromotion') {
if (empty($model->{$name_field})) {
throw new Exception("Invalid request. No {$name_field} found.");
}
$fileName = $model->{$name_field};
$checkSpace = explode(' ', $model->{$name_field});
if (count($checkSpace) > 1) {
$fileName = rawurlencode($fileName);
}
$src = "upload/promotion/{$folder}/" . $model->id . "/" . $fileName;
} else {
throw new Exception('Invalid request.');
}
$fileHelper = new FileHelper();
$fileHelper->forceDownload($src);
} catch (Exception $exc) {
throw new Exception($exc->getMessage());
}
}