PEEL Shopping
Open source ecommerce : PEEL Shopping
smarty_internal_write_file.php
Go to the documentation of this file.
1 <?php
17 
26  public static function writeFile($_filepath, $_contents, Smarty $smarty)
27  {
28  $_error_reporting = error_reporting();
29  error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
30  if ($smarty->_file_perms !== null) {
31  $old_umask = umask(0);
32  }
33 
34  $_dirpath = dirname($_filepath);
35  // if subdirs, create dir structure
36  if ($_dirpath !== '.' && !file_exists($_dirpath)) {
37  mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true);
38  }
39 
40  // write to tmp file, then move to overt file lock race condition
41  $_tmp_file = $_dirpath . DS . uniqid('wrt', true);
42  if (!file_put_contents($_tmp_file, $_contents)) {
43  error_reporting($_error_reporting);
44  throw new SmartyException("unable to write file {$_tmp_file}");
45  return false;
46  }
47 
48  /*
49  * Windows' rename() fails if the destination exists,
50  * Linux' rename() properly handles the overwrite.
51  * Simply unlink()ing a file might cause other processes
52  * currently reading that file to fail, but linux' rename()
53  * seems to be smart enough to handle that for us.
54  */
56  // remove original file
57  @unlink($_filepath);
58  // rename tmp file
59  $success = @rename($_tmp_file, $_filepath);
60  } else {
61  // rename tmp file
62  $success = @rename($_tmp_file, $_filepath);
63  if (!$success) {
64  // remove original file
65  @unlink($_filepath);
66  // rename tmp file
67  $success = @rename($_tmp_file, $_filepath);
68  }
69  }
70 
71  if (!$success) {
72  error_reporting($_error_reporting);
73  throw new SmartyException("unable to write file {$_filepath}");
74  return false;
75  }
76 
77  if ($smarty->_file_perms !== null) {
78  // set file permissions
79  @chmod($_filepath, $smarty->_file_perms);
80  umask($old_umask);
81  }
82  error_reporting($_error_reporting);
83  return true;
84  }
85 
86 }
87 
88 ?>
Smarty plugin to format text blocks.
static $_IS_WINDOWS
Flag denoting if operating system is windows.
static writeFile($_filepath, $_contents, Smarty $smarty)
Writes file in a safe way to disk.

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:41:17 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.