[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/include/inc_act/ -> act_ftptakeover.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // session_name('hashID');
  24  session_start();
  25  $phpwcms = array();
  26  
  27  require_once ('../../config/phpwcms/conf.inc.php');
  28  require_once  ('../inc_lib/default.inc.php');
  29  require_once  (PHPWCMS_ROOT.'/include/inc_lib/dbcon.inc.php');
  30  
  31  require_once  (PHPWCMS_ROOT.'/include/inc_lib/general.inc.php');
  32  checkLogin();
  33  require_once  (PHPWCMS_ROOT.'/include/inc_lib/backend.functions.inc.php');
  34  
  35  $ref = $_SESSION['REFERER_URL'];
  36  $ftp["error"] = 0;
  37  
  38  $ftp["mark"] = isset($_POST["ftp_mark"]) ? $_POST["ftp_mark"] : false;
  39  $ftp["file"] = isset($_POST["ftp_file"]) ? $_POST["ftp_file"] : false;
  40  
  41  if(is_array($ftp["mark"]) && count($ftp["mark"])) {
  42      foreach($ftp["mark"] as $key => $value) {
  43          if(intval($ftp["mark"][$key])) {
  44              $ftp["file"][$key] = base64_decode($ftp["file"][$key]);
  45          } else {
  46              unset($ftp["mark"][$key]);
  47              unset($ftp["file"][$key]);
  48          }
  49      }    
  50      if(!count($ftp["mark"])) $ftp["error"] = 1;    
  51  } else {
  52      $ftp["error"] = 1;
  53  }
  54  
  55  ?>
  56  <html>
  57  <head><title>phpwcms: creating thumbnail</title>
  58  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo PHPWCMS_CHARSET ?>">
  59  <meta http-equiv="Expires" content="0">
  60  <meta http-equiv="Pragma" content="no-cache">
  61  <meta http-equiv="cache-control" content="no-cache">
  62  <link href="../inc_css/phpwcms.css" rel="stylesheet" type="text/css">
  63  <style type="text/css">
  64  <!--
  65  body { background-color: #EBF2F4; }
  66  -->
  67  </style>
  68  </head>
  69  <body bgcolor="#EBF2F4" text="#000000" link="#000000" vlink="#000000" alink="#000000" leftmargin="15" topmargin="15" marginwidth="15" marginheight="15">
  70  <?php
  71  if(!$ftp["error"]) {
  72  
  73      $ftp["dir"]            = intval($_POST["file_dir"]);
  74      $ftp["short_info"]    = clean_slweg($_POST["file_shortinfo"]);
  75      
  76      $ftp["aktiv"]        = empty($_POST["file_aktiv"]) ? 0 : 1;
  77      $ftp["public"]        = empty($_POST["file_public"]) ? 0 : 1;
  78      $ftp["replace"]     = empty($_POST["file_replace"]) ? 0 : 1;
  79      $ftp["long_info"]    = clean_slweg($_POST["file_longinfo"]);
  80      $ftp["copyright"]    = clean_slweg($_POST["file_copyright"]);
  81      $ftp["tags"]        = trim( trim( clean_slweg($_POST["file_tags"]), ',') );
  82      
  83      $ftp["keywords"]    = isset($_POST["file_keywords"]) ? $_POST["file_keywords"] : array();
  84      $ftp["keys"]         = "";
  85      if(is_array($ftp["keywords"]) && count($ftp["keywords"])) {
  86          foreach($ftp["keywords"] as $key => $value) {
  87              unset($ftp["keywords"][$key]);
  88              $key = intval($key);
  89              if($value != "0_1") {
  90                  $ftp["keys"] .= (($ftp["keys"]) ? ":" : "").$key."_".intval($value);
  91                  $ftp["keywords"][$key] = intval($value);
  92              } else {
  93                  $file_error["keywords"][$key] = 1;
  94              }        
  95          }
  96      }
  97      
  98      
  99  ?><p><img src="../../img/symbole/rotation.gif" alt="" width="15" height="15"><strong class="title">&nbsp;selected files uploaded via ftp will be taken over!</strong></p><?php
 100  
 101      echo "<p class=\"v10\">";      
 102      flush();
 103      
 104      foreach($ftp["mark"] as $key => $value) {
 105          if(!ini_get('safe_mode') && function_exists('set_time_limit')) set_time_limit(60);
 106          
 107          $file = $ftp["file"][$key];
 108          $file_path = PHPWCMS_ROOT.$phpwcms["ftp_path"].$file;
 109          if(file_exists($file_path)) {
 110          
 111              $file_type = '';
 112              $file_error["upload"] = 0;
 113              $file_size    = filesize($file_path);
 114  
 115              $file_ext  = check_image_extension($file_path);
 116              $file_ext  = (false === $file_ext) ? which_ext($file) : $file_ext;
 117              
 118              $file_name = clearfilename( PHPWCMS_CHARSET != 'utf-8' && seems_utf8($file) ? utf8_decode($file) : $file);
 119              $file_hash = md5( $file_name . microtime() );
 120              
 121              
 122              if(trim($file_type) == '') {
 123      
 124                  //check file_type
 125                  if(is_mimetype_by_extension($file_ext)) {
 126                      $file_type = get_mimetype_by_extension($file_ext);
 127                  } else {
 128                      $file_check    = getimagesize($file_path);
 129                      if(version_compare("4.3.0", phpversion(), ">=") && $file_check) {
 130                          $file_type = image_type_to_mime_type($file_check[2]);
 131                      }
 132                      if(!trim($file_type)) {
 133                          $file_type = 'application/force-download';
 134                      }
 135                  }
 136              
 137              }
 138              
 139              $sql =  "INSERT INTO ".DB_PREPEND."phpwcms_file (".
 140                      "f_pid, f_uid, f_kid, f_aktiv, f_public, f_name, f_created, f_size, f_type, f_ext, ".
 141                      "f_shortinfo, f_longinfo, f_keywords, f_hash, f_copyright, f_tags) VALUES (".
 142                      $ftp["dir"].", ".intval($_SESSION["wcs_user_id"]).", 1, ".$ftp["aktiv"].", ".$ftp["public"].", '".
 143                      aporeplace($file_name)."', '".time()."', '".$file_size."', '".aporeplace($file_type)."', '".
 144                      aporeplace($file_ext)."', '".aporeplace($ftp["short_info"])."', '".
 145                      aporeplace($ftp["long_info"])."', '".$ftp["keys"]."', '".$file_hash."', '".
 146                      aporeplace($ftp["copyright"])."', '".aporeplace($ftp["tags"])."')";
 147                      
 148              if($result = mysql_query($sql, $db) or die("error while insert file information")) {
 149                  $new_fileId = mysql_insert_id($db); //Festlegen der aktuellen File-ID
 150                  
 151                  $_file_extension = ($file_ext) ? '.'.$file_ext : '';
 152                  $wcs_newfilename = $file_hash . $_file_extension;
 153  
 154                  // changed for using hashed file names
 155                  $userftppath    = PHPWCMS_ROOT.$phpwcms["ftp_path"];
 156                  $useruploadpath = PHPWCMS_ROOT.$phpwcms["file_path"];
 157                  $usernewfile    = $useruploadpath.$wcs_newfilename;
 158                  
 159                  
 160                  $oldumask = umask(0);
 161                  
 162                  if ($dir = @opendir($useruploadpath)) {
 163                      if(@copy($userftppath.$file, $usernewfile)) {
 164                          
 165                          @unlink($userftppath.$file);
 166                          
 167                          // store tags
 168                          _dbSaveCategories($ftp["tags"], 'file', $new_fileId, ',');
 169                          
 170                      } else {
 171                          $file_error["upload"] = "Error while writing file to storage (1).";
 172                      }
 173                  }
 174              }
 175              
 176              if(empty($file_error["upload"])) {
 177              
 178                  // now try to find 1st file having same named and replace it if related mark is set
 179                  if($ftp["replace"]) {
 180              
 181                      $rsql  = "SELECT * FROM ".DB_PREPEND."phpwcms_file WHERE ";
 182                      $rsql .= "f_name='".aporeplace($file_name)."' AND f_kid=1 ";
 183                      $rsql .= "AND f_pid=".$ftp["dir"]." AND f_trash=0 AND f_id != ".$new_fileId." LIMIT 1";
 184                      if($rresult = mysql_query($rsql, $db)) {
 185                      
 186                          if($rrow = mysql_fetch_assoc($rresult)) {
 187                          
 188                              $oldFileID      = $rrow['f_id'];
 189                              $oldFileHash    = $rrow['f_hash'];
 190                              $oldFileNewHash = md5( $file_name . microtime() . time() );
 191                          
 192                              // now update new file by old file information of same named
 193                              $nsql  = "UPDATE ".DB_PREPEND."phpwcms_file SET ";
 194                              $nsql .= "f_refid=".$oldFileID.", f_trash=5, f_size=".$rrow['f_size'].', ';
 195                              $nsql .= "f_type='".$rrow['f_type']."', f_changed=".now().', ';
 196                              $nsql .= "f_hash='".aporeplace($oldFileNewHash)."' WHERE f_id=".$new_fileId;
 197                              
 198                              if(mysql_query($nsql, $db)) {
 199                                  
 200                                  // yepp both files are updated in db
 201                                  // now change hash of file storage files
 202                                  rename($useruploadpath.$oldFileHash.$_file_extension, $useruploadpath.$oldFileNewHash.$_file_extension);
 203                                  rename($usernewfile, $useruploadpath.$oldFileHash.$_file_extension);
 204                                  
 205                                  // update file size of old file with new filesize
 206                                  _dbUpdate('phpwcms_file', array('f_type'=>$file_type, 'f_size'=>$file_size, 'f_changed'=>now()), 'f_id='.$oldFileID);
 207                                  
 208                                  //now try to delete all temp images if available
 209                                  $isql = "SELECT imgcache_imgname FROM ".DB_PREPEND."phpwcms_imgcache WHERE imgcache_hash='".aporeplace($oldFileHash)."'";
 210                                  if($iresult = mysql_query($isql, $db)) {
 211                                      $cImagePath = PHPWCMS_ROOT . '/' . PHPWCMS_IMAGES;
 212                                      while($irow = mysql_fetch_row($iresult)) {
 213                                          if(file_exists($cImagePath.$irow[0])) {
 214                                              @unlink($cImagePath.$irow[0]);
 215                                          }
 216                                      }
 217                                  }                
 218                              }
 219                          }
 220                          mysql_free_result($rresult);                
 221                      
 222                      }
 223              
 224              
 225                  }
 226                  
 227                  flush();
 228                  echo $file." [OK!]<br />";
 229              } else {
 230                  echo $file." (".$file_error["upload"].")<br />";
 231                  mysql_query("DELETE FROM ".DB_PREPEND."phpwcms_file WHERE f_id=".$new_fileId." AND f_uid=".$_SESSION["wcs_user_id"], $db);
 232              }
 233              
 234          } else {
 235              echo $file." not exists<br />";
 236          }
 237          flush();
 238      }
 239  echo "</p>\n";
 240  }
 241  
 242  if(empty($file_error["upload"]) && empty($ftp["error"])) {
 243      echo "<p class=\"title\"><strong>every selected file was taken over</strong></p>\n";
 244      echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a> (if no automatic redirect)</p>\n";
 245      echo "<script type=\"text/javascript\"> window.location.href = \"".$ref."\"; </script>\n";
 246      
 247  } else {
 248      echo "<p class=\"error\"><strong>error while file take over</strong></p>\n";
 249      echo "<p class='v10'><a href=\"".$ref."\" style=\"font-weight: bold;\">click here to go back</a></p>\n";
 250  }
 251  echo "</body>\n</html>\n";
 252  
 253  
 254  if(isset($oldumask)) {
 255      umask($oldumask);
 256  }
 257  
 258  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7