=====twomcm's user page===== These are two Wikka modules i have written. - The first, which i call 'blob', allows you to upload files ( up to 1 MiB (MySQL packet limit)) to a wikka powered site. As well, you can embed images into pages, create a link to the file, or show a description ( incl of view/download link ). It uses two files but the action file is all that is required if you only wish to upload or show the description view for files. - The second ( base64.php ) allows small files to be embeded into a page if they are base64 encoded ( not really suggested to be used ). Enjoy. Any comments would be appreciated. Since i do not have access to Internet Exploder YMMV if you are accessing these page with //that// browser. [[http://img82.imageshack.us/img82/7196/fileupload8kt.png | Screen shot of an example]] ( due to image editing problems, "Standard file embed" has Type: and Size: duplicated ). =====If you want to contact me use [[paranoidgeek@gmail.com]]===== I doubt if i will be visting this page often. =====Blob details :===== Blob ( as i have called it ) is [[Wikipedia:SHA1 | hash]] orientated. The three modes for displaying the file are : 1) **Description.** This gives a box with the file's details and allows has view and download buttons. Exmaple code : ""{{blob hash="SHA1 SUM"}}"" 1) **Image embed**. This inserts the image as ####. Also 'wrapped' with an #### pointing to the same URL as the img src. Requires the handerler file installed and the file's type must start with 'image' ( e.g. image/png). Example code : ""{{blob hash="SHA1 SUM" type="image"}}"" 1) **Image with border**. Same as above but with a border ( using class="border" ). Example code : ""{{blob hash="SHA1 SUM" type="image_wb"}}"" 1) **Link**. Just the file name wrapped with a #### pointing to the file's view URL. ---- ##/action/blob.php## %%(php) @author-nick twomcm @date November 2005 @version 1.1 @changlog 1.3 Image + link 1.2 Changed so that it will only allow uploads if the user has R/W to the page. 1.1 Minor bugs fixed 1.0 Complete 0.1 blank @license GPL v 2 @example List {{blob list="yes"}} Display {{blob hash="SHA1 SUM"}} Image {{blob hash="SHA1 SUM" type="image"}} link {{blob hash="SHA1 SUM" type="link"}} */ if($_POST['blob_sha1'] && !$_POST['blob_delete']){ // get file $row = $this->LoadSingle("SELECT LENGTH(`data`) as `size`, `hash`, `name`, `type`, `data` ". "FROM ".$this->config["table_prefix"]."blob WHERE `hash` = '".mysql_escape_string($_POST['blob_sha1'])."' "); if($row){ while(@ ob_end_clean()); // clean out every thing. header("Content-Length: ".$row['size']); header("Pragma: no-cache"); header("Content-Type: ".$row['type']); if($_POST['download'] ) header('Content-Disposition: attachment; filename="'.$row['name'].'"'); echo $row['data']; die(); }else{ while(@ ob_end_clean()); echo "Sorry the system was unable to find the requested item. \n"; die(); } }elseif(is_array($vars) && $vars['hash']){ $row = $this->LoadSingle("SELECT LENGTH(`data`) as `size`, `hash`, `name`, `type`, `upload_date` ". "FROM ".$this->config["table_prefix"]."blob WHERE `hash` = '".mysql_escape_string($vars['hash'])."' "); if($row){ if(strtolower($vars['type']) == 'link'){ echo "href('blob',$this->GetPageTag(),'action=view&hash='.$row['hash'])."\">"; echo "{$row['name']}"; echo ""; }elseif(strtolower($vars['type']) == 'image'){ echo "href('blob',$this->GetPageTag(),'action=view&hash='.$row['hash'])."\">"; echo " href('blob',$this->GetPageTag(),'action=view&hash='.$row['hash'])."\" />"; echo ""; }else{ echo $this->FormOpen(); echo "
\n"; echo "Filename: ".$row['name']."
\n"; echo "Type: ".$row['type']."
\n"; echo "Size: ".$row['size']." Bytes
\n"; echo "
\n"; echo '\n"; echo ''."\n"; echo ''."\n"; // FIXME remove unneeded style items echo $this->FormClose(); } }else{ echo "
\n"; echo "Sorry the system was unable to find the requested item.
\n"; echo "HASH : {$vars['hash']}\n"; echo "
\n"; } }elseif(is_array($vars) && $vars['list']){ // $var-list if($_POST['blob_delete'] && $this->HasAccess("write") ){ $this->Query("DELETE FROM ".$this->config["table_prefix"]."blob WHERE hash = '".$_POST['blob_sha1']."'"); unset($_POST['blob_delete']); unset($_POST['blob_sha1']); } if($_FILES['blob_upload']['name'] && $this->HasAccess("write") && !$_FILES['blob_upload']['error'] ){ $fileLocation = $_FILES['blob_upload']['tmp_name']; $fd = fopen($fileLocation, "r"); $t = fread($fd, filesize($fileLocation)); fclose($fd); unlink($fileLocation); if(strlen($t) <= 1000000){ // 1 million bytes $this->Query("INSERT INTO ".$this->config["table_prefix"]."blob ". "(`data`, `name`, `type`, `hash`, `upload_date`) ". "VALUES ('".mysql_escape_string($t)."' ,". // data "'".$_FILES['blob_upload']['name']."' ,". // name "'".$_FILES['blob_upload']['type']."' ,". // type "'".sha1($t)."', ". // hash " NOW() " . //upload_date ")") ; }else{ die ("Sorry the file you uploaded is too large ! You may only upload files of size 1MB or smaller."); } unset($t); } echo "\n"; $rows = $this->LoadAll("SELECT LENGTH(`data`) as `size`, `hash`, `name`, `type`, `upload_date` ". "FROM ".$this->config["table_prefix"]."blob ORDER BY `upload_date` DESC"); echo "\n"; foreach($rows as $row){ echo "". "". "". "". "". ""; echo ''."\n"; // view echo ''."\n"; // download echo ''."\n"; echo "\n"; } unset($rows); echo "
HashNameTypeSizeUpload Date
{$row['hash']}{$row['name']}{$row['type']}{$row['size']}".date("Y F j, G:i:s", strtotime($row['upload_date']))."'; echo $this->FormOpen(); echo '\n"; echo ''; echo $this->FormClose(); echo ''; echo $this->FormOpen(); echo '\n"; echo ''; echo $this->FormClose(); echo ''; if($this->HasAccess("write")){ echo $this->FormOpen(); echo '\n"; echo ''; // delete + js confirm echo $this->FormClose(); } echo '
\n"; if($this->HasAccess("write")){ echo"
href()."\" method=\"post\" enctype=\"multipart/form-data\">\n"; if (!$this->config["rewrite_mode"]) echo"MiniHref()."\">\n"; echo "\n"; echo "\n"; echo $this->FormClose(); } //.. upload }else{ // Bad setup echo "You have not configured the 'blob' action correctly."; } /* SQL for creating the table : CREATE TABLE `wikka_blob` ( `hash` varchar(40) NOT NULL default '', `name` varchar(255) NOT NULL default '', `type` varchar(255) NOT NULL default '', `upload_date` datetime NOT NULL default '0000-00-00 00:00:00', `data` mediumblob NOT NULL, PRIMARY KEY (`hash`) ) Type=MyISAM; */ ?> %% ---- ##/handlers/page/blob.php## %%(php) LoadSingle("SELECT LENGTH(`data`) as `size`, `hash`, `name`, `type`, `data` ". "FROM ".$this->config["table_prefix"]."blob WHERE `hash` = '".mysql_escape_string($_GET['hash'])."' "); if($row){ while(@ ob_end_clean()); // clean out every thing. header("Content-Length: ".$row['size']); header("Pragma: no-cache"); header("Content-Type: ".$row['type']); if($_GET['action'] == 'download' ) header('Content-Disposition: attachment; filename="'.$row['name'].'"'); echo $row['data']; die(); }else{ while(@ ob_end_clean()); echo "Sorry the system was unable to find the requested item. \n"; die(); } }else{ // Bad link echo "You have not configured the 'blob' handler correctly."; } ?> %% ---- /actions/base64.php %%(php) @date November 2005 @version 1.1 @changlog 1.1 Add view button 1.0 Changed to sending SHA to the script rather than the data. 0.9 Orginal version @license GPL v 2 @example This wikka example containes a random bit of data. {{base64 type="image/png" filename="pix1.png" data="FJSFNSIJFDisjdsjd=2/"}} */ if(is_array($vars) && $vars['data']){ $vars['data'] = preg_replace('/\s+/', '', $vars['data']); $filename = $vars['filename'] ? $vars['filename'] : 'Untitled.txt'; $size = (int)(strlen($vars['data'])*3/4); $type = $vars['type'] ? $vars['type'] : 'text/plain'; $sha1 = sha1($vars['data']); if($_POST['base64-sha1'] == $sha1){ while(@ ob_end_clean()); // clean out every thing. $data = base64_decode($vars['data']); header("Content-Length: ".strlen($data)); header("Pragma: no-cache"); header("Content-Type: $type"); if($_POST['download'] ) header("Content-Disposition: attachment; filename=\"$filename\""); echo $data; die(); }else{ echo $this->FormOpen(); echo "
\n"; echo "Filename: ".$filename."
\n"; echo "Type: ".$type."
\n"; echo "Size: ".$size." Bytes
\n"; echo "
\n"; echo ''."\n"; echo ''."\n"; // FIXME remove unneeded style items echo '\n"; echo $this->FormClose(); } }else{ echo "You have not configured the 'base64' action correctly."; } ?> %%