当前位置: 首页>>代码示例>>PHP>>正文


PHP OrderDetail::getDownloadFromHash方法代码示例

本文整理汇总了PHP中OrderDetail::getDownloadFromHash方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderDetail::getDownloadFromHash方法的具体用法?PHP OrderDetail::getDownloadFromHash怎么用?PHP OrderDetail::getDownloadFromHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OrderDetail的用法示例。


在下文中一共展示了OrderDetail::getDownloadFromHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: init

 public function init()
 {
     if (isset($this->context->employee) && $this->context->employee->isLoggedBack() && Tools::getValue('file')) {
         // Admin can directly access to file
         $filename = Tools::getValue('file');
         if (!Validate::isSha1($filename)) {
             die(Tools::displayError());
         }
         $file = _PS_DOWNLOAD_DIR_ . strval(preg_replace('/\\.{2,}/', '.', $filename));
         $filename = ProductDownload::getFilenameFromFilename(Tools::getValue('file'));
         if (empty($filename)) {
             $newFileName = Tools::getValue('filename');
             if (!empty($newFileName)) {
                 $filename = Tools::getValue('filename');
             } else {
                 $filename = 'file';
             }
         }
         if (!file_exists($file)) {
             Tools::redirect('index.php');
         }
     } else {
         if (!($key = Tools::getValue('key'))) {
             $this->displayCustomError('Invalid key.');
         }
         Tools::setCookieLanguage();
         if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key') && !Tools::getValue('id_order')) {
             Tools::redirect('index.php?controller=authentication&back=get-file.php&key=' . $key);
         } else {
             if (!$this->context->customer->isLogged() && Tools::getValue('secure_key') && Tools::getValue('id_order')) {
                 $order = new Order((int) Tools::getValue('id_order'));
                 if (!Validate::isLoadedObject($order)) {
                     $this->displayCustomError('Invalid key.');
                 }
                 if ($order->secure_key != Tools::getValue('secure_key')) {
                     $this->displayCustomError('Invalid key.');
                 }
             }
         }
         /* Key format: <sha1-filename>-<hashOrder> */
         $tmp = explode('-', $key);
         if (count($tmp) != 2) {
             $this->displayCustomError('Invalid key.');
         }
         $filename = $tmp[0];
         $hash = $tmp[1];
         if (!($info = OrderDetail::getDownloadFromHash($hash))) {
             $this->displayCustomError('This product does not exist in our store.');
         }
         /* Product no more present in catalog */
         if (!isset($info['id_product_download']) || empty($info['id_product_download'])) {
             $this->displayCustomError('This product has been deleted.');
         }
         if (!file_exists(_PS_DOWNLOAD_DIR_ . $filename)) {
             $this->displayCustomError('This file no longer exists.');
         }
         if (isset($info['product_quantity_refunded']) && isset($info['product_quantity_return']) && ($info['product_quantity_refunded'] > 0 || $info['product_quantity_return'] > 0)) {
             $this->displayCustomError('This product has been refunded.');
         }
         $now = time();
         $product_deadline = strtotime($info['download_deadline']);
         if ($now > $product_deadline && $info['download_deadline'] != '0000-00-00 00:00:00') {
             $this->displayCustomError('The product deadline is in the past.');
         }
         $customer_deadline = strtotime($info['date_expiration']);
         if ($now > $customer_deadline && $info['date_expiration'] != '0000-00-00 00:00:00') {
             $this->displayCustomError('Expiration date has passed, you cannot download this product');
         }
         if ($info['download_nb'] >= $info['nb_downloadable'] && $info['nb_downloadable']) {
             $this->displayCustomError('You have reached the maximum number of allowed downloads.');
         }
         /* Access is authorized -> increment download value for the customer */
         OrderDetail::incrementDownload($info['id_order_detail']);
         $file = _PS_DOWNLOAD_DIR_ . $info['filename'];
         $filename = $info['display_filename'];
     }
     /* Detect mime content type */
     $mimeType = false;
     if (function_exists('finfo_open')) {
         $finfo = @finfo_open(FILEINFO_MIME);
         $mimeType = @finfo_file($finfo, $file);
         @finfo_close($finfo);
     } else {
         if (function_exists('mime_content_type')) {
             $mimeType = @mime_content_type($file);
         } else {
             if (function_exists('exec')) {
                 $mimeType = trim(@exec('file -b --mime-type ' . escapeshellarg($file)));
                 if (!$mimeType) {
                     $mimeType = trim(@exec('file --mime ' . escapeshellarg($file)));
                 }
                 if (!$mimeType) {
                     $mimeType = trim(@exec('file -bi ' . escapeshellarg($file)));
                 }
             }
         }
     }
     if (empty($mimeType)) {
         $bName = basename($filename);
         $bName = explode('.', $bName);
//.........这里部分代码省略.........
开发者ID:FAVHYAN,项目名称:a3workout,代码行数:101,代码来源:GetFileController.php

示例2: Order

     $order = new Order((int) Tools::getValue('id_order'));
     if (!Validate::isLoadedObject($order)) {
         displayError('Invalid key.');
     }
     if ($order->secure_key != Tools::getValue('secure_key')) {
         displayError('Invalid key.');
     }
 }
 /* Key format: <sha1-filename>-<hashOrder> */
 $tmp = explode('-', $key);
 if (sizeof($tmp) != 2) {
     displayError('Invalid key.');
 }
 $filename = $tmp[0];
 $hash = $tmp[1];
 if (!($info = OrderDetail::getDownloadFromHash($hash))) {
     displayError('This product does not exist in our store.');
 }
 /* Product no more present in catalog */
 if (!isset($info['id_product_download']) or empty($info['id_product_download'])) {
     displayError('This product has been deleted.');
 }
 if (!file_exists(_PS_DOWNLOAD_DIR_ . $filename)) {
     displayError('This file no longer exists.');
 }
 $now = time();
 $product_deadline = strtotime($info['download_deadline']);
 if ($now > $product_deadline and $info['download_deadline'] != '0000-00-00 00:00:00') {
     displayError('The product deadline is in the past.');
 }
 $customer_deadline = strtotime($info['date_expiration']);
开发者ID:hecbuma,项目名称:quali-fisioterapia,代码行数:31,代码来源:get-file.php


注:本文中的OrderDetail::getDownloadFromHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。