本文整理匯總了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());
}
}