1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
|
<?php
/**
* Class datei (file) provides methods to handle files and folders
*
* @author Philipp Kiszka <info@o-dyn.de>
* @name datei
* @package Collabtive
* @version 2.0
* @link http://www.o-dyn.de
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License v3 or later
*/
class datei {
/**
* Constructor
*
* @access protected
*/
function __construct()
{
// Initialize event log
$this->mylog = new mylog;
}
// FOLDER METHODS
/**
* Create a new folder
*
* @param int $parent ID of the parent folder
* @param int $project ID of the project the folder belongs to
* @param string $folder Name of the new folder
* @param string $desc Description of the new folder
* @param strin $visible Visibility of the new folder
* @return bool
*/
function addFolder($parent, $project, $folder, $desc)
{
global $conn;
$project = (int) $project;
$folderOrig = $folder;
$thepath = $this->getAbsolutePathName($this->getFolder($parent));
//if its the root path, don't append any slashes
if($thepath == "/")
{
$thepath = "";
}
// Replace umlauts
$folder = str_replace("ä", "ae" , $folder);
$folder = str_replace("ö", "oe" , $folder);
$folder = str_replace("ü", "ue" , $folder);
$folder = str_replace("ß", "ss" , $folder);
// Remove whitespace
$folder = preg_replace("/\W/", "", $folder);
$folder = preg_replace("/[^-_0-9a-zA-Z]/", "_", $folder);
// Insert folder into database
$insStmt = $conn->prepare("INSERT INTO projectfolders (parent, project, name, description) VALUES (?, ?, ?, ?)");
$ins = $insStmt->execute(array($parent, $project, $folder, $desc));
if ($ins) {
// Create the folder
//$makefolder = CL_ROOT . "/files/" . CL_CONFIG . "/$project/$folder/";
$makefolder = CL_ROOT . "/files/" . CL_CONFIG . "/$project" . $thepath . "/" . $folder . "/";
//echo "<br><br>" . $makefolder . "<br>" . $makefolder2;
if (!file_exists($makefolder)) {
if (mkdir($makefolder, 0777, true)) {
// Folder created
$this->mylog->add($folderOrig, 'folder', 1, $project);
return true;
}
} else {
// Folder already existed, return false
return false;
}
} else {
// Folder could not be created, return false
return false;
}
}
/**
* Delete a folder
* Deletes the given folder as well as all of its files and subfolders.
*
* @param int $id Folder ID
* @param int $project Project ID
* @return bool
*/
function deleteFolder($id, $project)
{
global $conn;
$id = (int) $id;
$project = (int) $project;
$folder = $this->getFolder($id);
$files = $this->getProjectFiles($project, 10000, $id);
// Delete all files in the folder from database and filesystem
if (!empty($files)) {
foreach($files as $file) {
$this->loeschen($file["ID"]);
}
}
// Recursively delete any nested subfolders
if (!empty($folder["subfolders"])) {
foreach($folder["subfolders"] as $sub) {
$this->deleteFolder($sub["ID"], $sub["project"]);
}
}
$del = $conn->query("DELETE FROM projectfolders WHERE ID = $id");
if ($del) {
// Remove directory
$foldstr = CL_ROOT . "/files/" . CL_CONFIG . "/$project/" . $folder["name"] . "/";
delete_directory($foldstr);
$this->mylog->add($folder["name"], 'folder', 3, $project);
return true;
}
}
/**
* Get a folder
*
* @param int $id Folder ID
* @return array $folder
*/
function getFolder($id)
{
global $conn;
$id = (int) $id;
$qry = $conn->query("SELECT * FROM projectfolders WHERE ID = $id LIMIT 1");
if ($qry) {
$folder = $qry->fetch();
if(!$folder)
{
return false;
}
$folder["subfolders"] = $this->getSubFolders($folder["ID"]);
$folder["abspath"] = $this->getAbsolutePathName($folder);
}
return $folder;
}
/**
* Recursively get all subfolders of a folder
*
* @param int $parent ID of the parent folder
* @return array $folders
*/
function getSubFolders($parent)
{
global $conn;
$parent = (int) $parent;
$sel = $conn->query("SELECT * FROM projectfolders WHERE parent = $parent ORDER BY ID ASC");
$folders = array();
while ($sel and $folder = $sel->fetch()) {
$folder["subfolders"] = $this->getSubFolders($folder["ID"]);
$folder["abspath"] = $this->getAbsolutePathName($folder);
array_push($folders, $folder);
}
if (!empty($folders)) {
return $folders;
} else {
return false;
}
}
/**
* Get all the folders in a project, starting from a given folder
*
* @param int $project Project ID
* @param int $parent Parent folder ID (default: 0 => root folder)
* @return array $folders
*/
function getProjectFolders($project, $parent = 0)
{
global $conn;
$parent = (int) $parent;
$project = (int) $project;
$sel = $conn->query("SELECT * FROM projectfolders WHERE project = $project AND parent = $parent ORDER BY ID ASC");
$folders = array();
while ($sel and $folder = $sel->fetch()) {
$folder["subfolders"] = $this->getSubFolders($folder["ID"]);
$folder["abspath"] = $this->getAbsolutePathName($folder);
array_push($folders, $folder);
}
if (!empty($folders)) {
return $folders;
} else {
return false;
}
}
/**
* Get all the folders in a project
*
* @param string $id project Project ID
* @return array $folders
*/
function getAllProjectFolders($project)
{
global $conn;
$project = (int) $project;
$sel = $conn->query("SELECT * FROM projectfolders WHERE project = $project ORDER BY ID ASC");
$folders = array();
while ($sel and $folder = $sel->fetch()) {
$folder["subfolders"] = $this->getSubFolders($folder["ID"]);
$folder["abspath"] = $this->getAbsolutePathName($folder);
array_push($folders, $folder);
}
if (!empty($folders)) {
return $folders;
} else {
return false;
}
}
/**
* Get an absolute path name of a folder
* Returns the absolute name (relative to the root directory of the project) of a folder.
*
* @param array $folder The folder to be inspected
* @return string Absolute path/name of the folder
*/
function getAbsolutePathName($folder)
{
global $conn;
if ($folder['parent'] == 0) {
return "/" . $folder['name'];
} else {
$sel = $conn->query("SELECT * FROM projectfolders WHERE ID = " . $folder['parent']);
if ($sel) {
$parent = $sel->fetch();
}
return $this->getAbsolutePathName($parent) . "/" . $folder['name'];
}
}
// FILE METHODS
/**
* Upload a file
* Does filename sanitizing as well as MIME-type determination
* Also adds the file to the database using add_file()
*
* @param string $fname Name of the HTML form field POSTed from
* @param string $ziel Destination directory
* @param int $project Project ID of the associated project (default: 0 => root folder)
* @param int $folder
* @return bool
*/
function upload($fname, $ziel, $project, $folder = 0)
{
echo $fname . " " . $ziel . " " . $project;
// Get data from form
$name = $_FILES[$fname]['name'];
$typ = $_FILES[$fname]['type'];
$size = $_FILES[$fname]['size'];
$tmp_name = $_FILES[$fname]['tmp_name'];
$tstr = $fname . "-title";
$tastr = $fname . "-tags";
$title = $_POST[$tstr];
$error = $_FILES[$fname]['error'];
$root = CL_ROOT;
// If no filename is given, abort
if (empty($name)) {
return false;
}
$desc = $_POST['desc'];
// Find the extension
$teilnamen = explode(".", $name);
$teile = count($teilnamen);
$workteile = $teile - 1;
$erweiterung = $teilnamen[$workteile];
$subname = "";
// If it is a PHP file, treat it as plain text so it is not executed when opened in the browser
if (stristr($erweiterung, "php")) {
$erweiterung = "txt";
$typ = "text/plain";
}
// Reassemble the file name from the exploded array, without the extension
for ($i = 0; $i < $workteile; $i++) {
$subname .= $teilnamen[$i];
}
// Create a random number
$randval = mt_rand(1, 99999);
// Only allow a-z, 0-9 in filenames, substitute other chars with _
$subname = str_replace("ä", "ae" , $subname);
$subname = str_replace("Ä", "Ae" , $subname);
$subname = str_replace("ö", "oe" , $subname);
$subname = str_replace("Ö", "Oe" , $subname);
$subname = str_replace("ü", "ue" , $subname);
$subname = str_replace("Ü", "Ue" , $subname);
$subname = str_replace("ß", "ss" , $subname);
$subname = preg_replace("/[^-_0-9a-zA-Z]/", "_", $subname);
// Remove whitespace
$subname = preg_replace("/\W/", "", $subname);
// If filename is longer than 200 chars, cut it
if (strlen($subname) > 200) {
$subname = substr($subname, 0, 200);
}
// Assemble the final filename from the original name plus the random value.
// This is to ensure that files with the same name do not overwrite each other.
$name = $subname . "_" . $randval . "." . $erweiterung;
// Absolute file system path used to move the file to its final location
$datei_final = $root . "/" . $ziel . "/" . $name;
// Relative path used for display / URL construction in the file manager
$datei_final2 = $ziel . "/" . $name;
if (!file_exists($datei_final)) {
if (move_uploaded_file($tmp_name, $datei_final)) {
if ($project > 0) {
// File did not already exist, was uploaded, and a project is set
// Now add the file to the database, log the upload event and return the file ID
chmod($datei_final, 0755);
$fid = $this->add_file($name, $desc, $project, 0, $datei_final2, "$typ", $title, $folder, "");
if (!empty($title)) {
$this->mylog->add($title, 'file', 1, $project);
} else {
$this->mylog->add($name, 'file', 1, $project);
}
//encrypt the uploaded file
$this->encryptFile($datei_final);
return $fid;
} else {
// No project means the file is not added to the database willfully. Return file name
return $name;
}
} else {
// File was not uploaded / error occured. Return false
return false;
}
} else {
// File already exists. Return false
return false;
}
}
/**
* Upload a file
* Does filename sanitizing as well as MIME-type determination
* Also adds the file to the database using add_file()
*
* @param string $fname Name of the HTML form field POSTed from
* @param string $ziel Destination directory
* @param int $project Project ID of the associated project
* @return bool
*/
function uploadAsync($name, $tmp_name, $typ, $size, $ziel, $project, $folder = 0)
{
$visible = "";
$visstr = "";
$root = CL_ROOT;
if (empty($name)) {
return false;
}
// Find the extension
$teilnamen = explode(".", $name);
$teile = count($teilnamen);
$workteile = $teile - 1;
$erweiterung = $teilnamen[$workteile];
$subname = "";
// If it is a PHP file, treat as plain text so it is not executed when opened in the browser
if (stristr($erweiterung, "php")) {
$erweiterung = "txt";
$typ = "text/plain";
}
for ($i = 0; $i < $workteile; $i++) {
$subname .= $teilnamen[$i];
}
$randval = mt_rand(1, 99999);
// Only allow a-z, 0-9 in filenames, substitute other chars with _
$subname = str_replace("ä", "ae" , $subname);
$subname = str_replace("Ä", "Ae" , $subname);
$subname = str_replace("ö", "oe" , $subname);
$subname = str_replace("Ö", "Oe" , $subname);
$subname = str_replace("ü", "ue" , $subname);
$subname = str_replace("Ü", "Ue" , $subname);
$subname = str_replace("ß", "ss" , $subname);
$subname = preg_replace("/[^-_0-9a-zA-Z]/", "_", $subname);
// Remove whitespace
$subname = preg_replace("/\W/", "", $subname);
// If filename is longer than 200 chars, cut it
if (strlen($subname) > 200) {
$subname = substr($subname, 0, 200);
}
$name = $subname . "_" . $randval . "." . $erweiterung;
$datei_final = $root . "/" . $ziel . "/" . $name;
$datei_final2 = $ziel . "/" . $name;
if (!file_exists($datei_final)) {
if (move_uploaded_file($tmp_name, $datei_final)) {
if ($project > 0) {
// File did not already exist, was uploaded, and a project is set
// Now add the file to the database, log the upload event and return the file ID.
if (!$title) {
$title = $name;
}
chmod($datei_final, 0755);
$fid = $this->add_file($name, $desc, $project, 0, $datei_final2, "$typ", $title, $folder, "");
if (!empty($title)) {
$this->mylog->add($title, 'file', 1, $project);
} else {
$this->mylog->add($name, 'file', 1, $project);
}
//encrypt the uploaded file
//$this->encryptFile($datei_final);
return $fid;
} else {
// No project means the file is not added to the database wilfully. Return file name
return $name;
}
} else {
// File was not uploaded / error occured. Return false
return false;
}
} else {
// File already exists. Return false
return false;
}
}
/**
* Edit a file
*
* @param int $id File ID
* @param string $title Title of the file
* @param string $desc Description text
* @param string $tags Associated tags (not yet implemented)
* @return bool
*/
function edit($id, $title, $desc, $tags)
{
global $conn;
$id = (int) $id;
// Get project for logging
$qry = $conn->query("SELECT project FROM files WHERE ID = $id");
if ($qry) {
$project = $qry->fetch();
$project = $proj[0];
}
$sql = $conn->prepare("UPDATE files SET `title` = ?, `desc` = ?, `tags` = ? WHERE id = ?");
$upd = $sql->execute(array($title, $desc, $tags, $id));
if ($sql) {
$this->mylog->add($title, 'file' , 2, $project);
return true;
} else {
return false;
}
}
/**
* Delete a file
*
* @param int $datei File ID
* @return bool
*/
function loeschen($datei)
{
global $conn;
$datei = (int) $datei;
$qry = $conn->query("SELECT datei, name, project, title FROM files WHERE ID = $datei");
if ($qry) {
$thisfile = $qry->fetch();
}
if (!empty($thisfile)) {
$fname = $thisfile[1];
$project = $thisfile[2];
$ftitle = $thisfile[3];
$thisfile = $thisfile[0];
$delfile = "./" . $thisfile;
if (!file_exists($delfile)) {
return false;
}
$del = $conn->query("DELETE FROM files WHERE ID = $datei");
// Delete attachments of the file (prevents abandoned objects in messages)
$del2 = $conn->query("DELETE FROM files_attached WHERE file = $datei");
if ($del) {
// Only remove the file from file system if deletion from database was successful
if (unlink($delfile)) {
if ($ftitle != "") {
$this->mylog->add($ftitle, 'file', 3, $project);
} else {
$this->mylog->add($fname, 'file', 3, $project);
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}
/**
* Return a file
*
* @param string $id File ID
* @return array $file File details
*/
function getFile($id)
{
global $conn;
$id = (int) $id;
// Get the file from the database
$qry = $conn->query("SELECT * FROM files WHERE ID=$id");
if ($qry) {
$file = $qry->fetch();
}
if (!empty($file)) {
// Determine if there is a MIME-type icon corresponding to the file's MIME-type. If not, set 'none'
$file['type'] = str_replace("/", "-", $file["type"]);
// Get settings (needed to add a different MIME-type icon per theme for each file)
$set = new settings();
$settings = $set->getSettings();
// Construct the path to the MIME-type icon
$myfile = "./templates/" . $settings["template"] . "/theme/" . $settings["theme"] . "/images/files/" . $file['type'] . ".png";
if (!file_exists($myfile)) {
$file['type'] = "none";
}
// Determine if it is an image or text file or some other kind of file (required for lightbox)
if (stristr($file['type'], "image")) {
$file['imgfile'] = 1;
} elseif (stristr($file['type'], "text")) {
$file['imgfile'] = 0;
} else {
$file['imgfile'] = 0;
}
// Strip slashes from title, desc and tags
$file["title"] = stripslashes($file["title"]);
$file["desc"] = stripslashes($file["desc"]);
$file["size"] = filesize(realpath($file["datei"])) / 1024;
$file["size"] = round($file["size"]);
$file["addedstr"] = date(CL_DATEFORMAT, $file["added"]);
// Attach data about the user who uploaded the file
$userobj = new user();
$file["userdata"] = $userobj->getProfile($file["user"]);
return $file;
} else {
return false;
}
}
/**
* Move a file to another folder
*
* @param int $file File ID
* @param int $folder Folder ID
* @return bool
*/
function moveFile($file, $target)
{
global $conn;
$file = (int) $file;
$target = (int)$target;
// Get the file
$thefile = $this->getFile($file);
// Get the target folder
$thefolder = $this->getFolder($target);
$abspath = $this->getAbsolutePathName($thefolder);
if($abspath == "/")
{
$abspath = "";
}
// Build file system paths
//$targetstr = "files/" . CL_CONFIG . "/" . $thefile["project"] . "/" . $thefolder["name"] . "/" . $thefile["name"];
$targetstr = "files/" . CL_CONFIG . "/" . $thefile["project"] . $abspath . "/" . $thefile["name"];
$rootstr = CL_ROOT . "/" . $thefile["datei"];
// Update database
$upd = $conn->query("UPDATE files SET datei = '$targetstr', folder = '$thefolder[ID]' WHERE ID = $thefile[ID]");
// Move the file physically
return rename($rootstr, $targetstr);
}
/**
* List all files associated to a given project
*
* @param string $id Project ID
* @param int $lim Limit
* @param int $folder Folder
* @return array $files Found files
*/
function getProjectFiles($id, $lim = 5000, $folder = "")
{
global $conn;
$id = (int) $id;
$lim = (int) $lim;
$folder = (int) $folder;
// If folder is given, return files from this folder, otherwise return files from root folder
if ($folder > 0) {
$fold = "files/" . CL_CONFIG . "/$id/$folder/";
$sel = $conn->query("SELECT COUNT(*) FROM files WHERE project = $id AND folder = $folder ORDER BY ID DESC");
} else {
$sel = $conn->query("SELECT COUNT(*) FROM files WHERE project = $id AND folder = 0 ORDER BY ID DESC");
}
if ($sel) {
$num = $sel->fetch();
$num = $num[0];
}
// Set items per page
SmartyPaginate::connect();
SmartyPaginate::setLimit($lim);
SmartyPaginate::setTotal($num);
$start = SmartyPaginate::getCurrentIndex();
$lim = SmartyPaginate::getLimit();
$files = array();
if ($folder > 0) {
$sql = "SELECT ID FROM files WHERE project = $id AND folder = $folder ORDER BY ID DESC LIMIT $start,$lim";
$sel2 = $conn->query($sql);
} else {
$sel2 = $conn->query("SELECT ID FROM files WHERE project = $id AND folder = 0 ORDER BY ID DESC LIMIT $start,$lim");
} while ($sel2 and $file = $sel2->fetch()) {
if (!empty($file)) {
array_push($files, $this->getFile($file["ID"]));
}
}
if (!empty($files)) {
return $files;
} else {
return false;
}
}
/**
* List all files associated to a given project regardless of folder
*
* @param string $id Project ID
* @return array $files Found files
*/
function getAllProjectFiles($id)
{
global $conn;
$id = (int) $id;
$files = array();
$sel2 = $conn->query("SELECT ID FROM files WHERE project = $id ORDER BY ID DESC");
while ($sel2 and $file = $sel2->fetch()) {
if (!empty($file)) {
array_push($files, $this->getFile($file["ID"]));
}
}
if (!empty($files)) {
return $files;
} else {
return false;
}
}
/**
* Seed the random number generator
*
* @return float $value Initial value
*/
private function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
$value = (float) $sec + ((float) $usec * 100000);
return $value;
}
/**
* Add a file to the database
*
* @param string $name File name
* @param string $desc Description
* @param int $project ID of the associated project
* @param int $milestone ID of the associated milestone
* @param string $tags Tags for the file (not yet implemented)
* @param string $datei File path
* @param string $type MIME type
* @param string $title Title of the file
* @param int $ folder Optional parameter (holds ID of subfolder the file is uploaded to [0 = root directory])
* @return bool $insid
*/
function add_file($name, $desc, $project, $milestone, $datei, $type, $title = " ", $folder = 0, $visstr = "")
{
global $conn;
if (!$desc) {
$desc = " ";
}
$project = (int) $project;
$milestone = (int) $milestone;
$folder = (int) $folder;
$userid = $_SESSION["userid"];
$now = time();
$insStmt = $conn->prepare("INSERT INTO files (`name`, `desc`, `project`, `milestone`, `user`, `added`, `datei`, `type`, `title`, `folder`, `visible`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$ins = $insStmt->execute(array($name, $desc, $project, $milestone, $userid, $now, $datei, $type, $title, $folder, $visstr));
if ($ins) {
$insid = $conn->lastInsertId();
return $insid;
} else {
return false;
}
}
function encryptFile($filename, $key)
{
include_once(CL_ROOT . "/include/phpseclib/Crypt/AES.php");
$cipher = new Crypt_AES(); // could use CRYPT_AES_MODE_CBC
$cipher->setPassword($key);
$plaintext = file_get_contents($filename);
//echo $cipher->decrypt($cipher->encrypt($plaintext));
return file_put_contents($filename,$cipher->encrypt($plaintext));
}
function decryptFile($filename, $key)
{
include_once(CL_ROOT . "/include/phpseclib/Crypt/AES.php");
$cipher = new Crypt_AES(); // could use CRYPT_AES_MODE_CBC
$cipher->setPassword($key);
$ciphertext = file_get_contents($filename);
//echo $cipher->decrypt($cipher->encrypt($plaintext));
return $cipher->decrypt($ciphertext);
}
}
?>
|