Items:Download File v2
From SMFShopWiki
| Download File v2 | |
| Latest Item Version: | SMFShop 1.2-Fixed1 |
|---|---|
| SMFShop Version Required: | Any |
| PHP Version Required: | Any |
| MySQL Version Required: | Any |
The 'Download File v2' item is a modified version of the 'Download File' item included with SMFShop. It allows files larger than 10 MB to be used. Basically, the item that comes with SMFShop reads the whole file into memory, which doesn't work for large files. This item instead reads the file in 1 MB chunks, which is more efficient for larger files.
This file should be saved as filedownload2.php.
<?php /**********************************************\ | SMFSHOP (Shop MOD for Simple Machines Forum) | | (c) 2005 DanSoft Australia | | http://www.dansoftaus.uni.cc/ | \**********************************************/ //File: filedownload2.php // File Download Item //VERSION: 1.2 (Build 5) --Fixed v1 //DATE: 15th April 2006 class item_filedownload2 extends itemTemplate { function getItemDetails() { $this->name = "Download xxx File v2"; $this->desc = "Download a file [INSERT FILE DESCRIPTION HERE]"; $this->price = 200; $this->require_input = false; $this->can_use_item = true; } //see AddToPostCount for more info function getAddInput() { return "File Name: <input type='text' name='info1' value='file_name_here.txt' size='60'><br> This file name does NOT need to be the same name as the file on the server. This name is what the file will be saved as on the user's computer.<br><br> File Path (INCLUDING FILE NAME): <input type='text' name='info2' value='../../file_name_here.txt' size='60'><br> <b>IMPORTANT: </b>Make SURE that this file path is <b>OUT of your webroot.</b> If your forum is stored at /home/myuser/public_html/forum/ then store the downloadable file at /home/myuser/files/ or similar. Otherwise, you run the risk of the file being downloaded without being paid for.<br> <input type='checkbox' name='info3'>Delete item from inventory after use"; } function onUse() { readfile_chunked($item_info[2], false); $result = db_query("DELETE FROM {$db_prefix}shop_inventory WHERE id = {$_GET['id']}", __FILE__, __LINE__); } } } function readfile_chunked($filename,$retbytes=true) { $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $cnt =0; // $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } echo $buffer; if ($retbytes) { } } if ($retbytes && $status) { return $cnt; // return num. bytes delivered like readfile() does. } return $status; } ?>
