/media/vm_4a2d49bdca83c/install.copy.php

https://github.com/shafiqissani/Jewelery-Ecommerce- · PHP · 201 lines · 133 code · 14 blank · 54 comment · 28 complexity · 6697020a59b4c6b49092cb32cd1cf4b4 MD5 · raw file

  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) {
  3. die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  4. }
  5. // copydirr.inc.php
  6. /*
  7. http://de3.php.net/manual/de/function.copy.php#55130
  8. 26.07.2005
  9. Author: Anton Makarenko
  10. makarenkoa at ukrpost dot net
  11. webmaster at eufimb dot edu dot ua
  12. */
  13. function copydirr($fromDir,$toDir,$chmod=0757,$verbose=false)
  14. /*
  15. copies everything from directory $fromDir to directory $toDir
  16. and sets up files mode $chmod
  17. */
  18. {
  19. //* Check for some errors
  20. $errors=array();
  21. $messages=array();
  22. if (!is_writable($toDir)) {
  23. $errors[]='target '.$toDir.' is not writable';
  24. }
  25. if (!is_dir($toDir)) {
  26. $errors[]='target '.$toDir.' is not a directory';
  27. }
  28. if (!is_dir($fromDir)) {
  29. $errors[]='source '.$fromDir.' is not a directory';
  30. }
  31. if (!empty($errors))
  32. {
  33. if ($verbose) {
  34. foreach($errors as $err) {
  35. echo '<strong>Error</strong>: '.$err.'<br />';
  36. }
  37. }
  38. return false;
  39. }
  40. //*/
  41. $exceptions=array('.','..');
  42. //* Processing
  43. $handle=opendir($fromDir);
  44. while (false!==($item=readdir($handle)))
  45. if (!in_array($item,$exceptions))
  46. {
  47. //* cleanup for trailing slashes in directories destinations
  48. $from=str_replace('//','/',$fromDir.'/'.$item);
  49. $to=str_replace('//','/',$toDir.'/'.$item);
  50. //*/
  51. if (is_file($from))
  52. {
  53. if (@copy($from,$to))
  54. {
  55. chmod($to,$chmod);
  56. touch($to,filemtime($from)); // to track last modified time
  57. $messages[]='File copied from '.$from.' to '.$to;
  58. }
  59. else
  60. $errors[]='cannot copy file from '.$from.' to '.$to;
  61. }
  62. if (is_dir($from))
  63. {
  64. if (@mkdir($to))
  65. {
  66. chmod($to,$chmod);
  67. $messages[]='Directory created: '.$to;
  68. }
  69. else
  70. $errors[]='cannot create directory '.$to;
  71. copydirr($from,$to,$chmod,$verbose);
  72. }
  73. }
  74. closedir($handle);
  75. //*/
  76. //* Output
  77. if ($verbose)
  78. {
  79. foreach($errors as $err)
  80. echo '<strong>Error</strong>: '.$err.'<br />';
  81. foreach($messages as $msg)
  82. echo $msg.'<br />';
  83. }
  84. //*/
  85. return true;
  86. }
  87. /**
  88. * Replace file_get_contents()
  89. *
  90. * @category PHP
  91. * @package PHP_Compat
  92. * @link http://php.net/function.file_get_contents
  93. * @author Aidan Lister <aidan@php.net>
  94. * @version $Revision: 617 $
  95. * @internal resource_context is not supported
  96. * @since PHP 5
  97. * @require PHP 4.0.1 (trigger_error)
  98. */
  99. if (!function_exists('file_get_contents')) {
  100. function file_get_contents($filename, $incpath = false, $resource_context = null)
  101. {
  102. if (false === $fh = fopen($filename, 'rb', $incpath)) {
  103. trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
  104. return false;
  105. }
  106. clearstatcache();
  107. if ($fsize = @filesize($filename)) {
  108. $data = fread($fh, $fsize);
  109. } else {
  110. $data = '';
  111. while (!feof($fh)) {
  112. $data .= fread($fh, 8192);
  113. }
  114. }
  115. fclose($fh);
  116. return $data;
  117. }
  118. }
  119. if (!defined('FILE_USE_INCLUDE_PATH')) {
  120. define('FILE_USE_INCLUDE_PATH', 1);
  121. }
  122. if (!defined('FILE_APPEND')) {
  123. define('FILE_APPEND', 8);
  124. }
  125. /**
  126. * Replace file_put_contents()
  127. *
  128. * @category PHP
  129. * @package PHP_Compat
  130. * @link http://php.net/function.file_put_contents
  131. * @author Aidan Lister <aidan@php.net>
  132. * @version $Revision: 617 $
  133. * @internal resource_context is not supported
  134. * @since PHP 5
  135. * @require PHP 4.0.1 (trigger_error)
  136. */
  137. if (!function_exists('file_put_contents')) {
  138. function file_put_contents($filename, $content, $flags = null, $resource_context = null)
  139. {
  140. // If $content is an array, convert it to a string
  141. if (is_array($content)) {
  142. $content = implode('', $content);
  143. }
  144. // If we don't have a string, throw an error
  145. if (!is_scalar($content)) {
  146. trigger_error('file_put_contents() The 2nd parameter should be either a string or an array', E_USER_WARNING);
  147. return false;
  148. }
  149. // Get the length of date to write
  150. $length = strlen($content);
  151. // Check what mode we are using
  152. $mode = ($flags & FILE_APPEND) ?
  153. $mode = 'a' :
  154. $mode = 'w';
  155. // Check if we're using the include path
  156. $use_inc_path = ($flags & FILE_USE_INCLUDE_PATH) ?
  157. true :
  158. false;
  159. // Open the file for writing
  160. if (($fh = @fopen($filename, $mode, $use_inc_path)) === false) {
  161. trigger_error('file_put_contents() failed to open stream: Permission denied', E_USER_WARNING);
  162. return false;
  163. }
  164. // Write to the file
  165. $bytes = 0;
  166. if (($bytes = @fwrite($fh, $content)) === false) {
  167. $errormsg = sprintf('file_put_contents() Failed to write %d bytes to %s',
  168. $length,
  169. $filename);
  170. trigger_error($errormsg, E_USER_WARNING);
  171. return false;
  172. }
  173. // Close the handle
  174. @fclose($fh);
  175. // Check all the data was written
  176. if ($bytes != $length) {
  177. $errormsg = sprintf('file_put_contents() Only %d of %d bytes written, possibly out of free disk space.',
  178. $bytes,
  179. $length);
  180. trigger_error($errormsg, E_USER_WARNING);
  181. return false;
  182. }
  183. // Return length
  184. return $bytes;
  185. }
  186. }
  187. ?>