Last active
June 26, 2019 14:17
-
-
Save eto4detak/6f7997959f735f930b36498391de4496 to your computer and use it in GitHub Desktop.
php delete-files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Delete old LOG files | |
*/ | |
$path = $this_dir . '/logs/'; | |
$days = 90; | |
// Open the directory | |
if ($handle = opendir($path)) { | |
// Loop through the directory | |
while (false !== ($file = readdir($handle))) { | |
// Check the file we're doing is actually a file | |
if (is_file($path . $file)) { | |
// Check if the file is older than X days old | |
if (filemtime($path . $file) < (time() - ($days * 24 * 60 * 60))) { | |
// Do the deletion | |
unlink($path . $file); | |
} | |
} | |
} | |
} | |
// create | |
define("XDP_DIR_XLS", wp_upload_dir()['basedir']. '/xsl-update-products/'); | |
define("XDP_FILE_XLS", wp_upload_dir()['basedir']. '/xsl-update-products/file-updated-products.xls'); | |
define("XDP_URL_XLS", wp_upload_dir()['baseurl']. '/xsl-update-products/file-updated-products.xls'); | |
$path = $_FILES['my_xls_upload']['tmp_name']; | |
xdp_load_to_main_file($path); | |
// file_put_contents($path, $current); | |
function xdp_load_to_main_file($path) | |
{ | |
$file = file_get_contents($path); | |
if (!file_exists(XDP_FILE_XLS)) { | |
mkdir(XDP_DIR_XLS, 0777); | |
$fp = fopen(XDP_FILE_XLS, "w"); | |
$fwrite_return = fwrite($fp, $file); | |
fclose($fp); | |
}else{ | |
$fp = fopen(XDP_FILE_XLS, "w"); | |
$fwrite_return = fwrite($fp, $file); | |
fclose($fp); | |
} | |
return $fwrite_return; | |
} | |
// | |
$url = 'https://klinker.msk.ru/wp-content/uploads/xls-update-products/file-updated-products.xls'; | |
if (!file_exists(XUP_FILE_XLS)) { | |
mkdir(XUP_DIR_XLS, 0777); | |
$fp = fopen(XUP_FILE_XLS, "w"); | |
$fwrite_return = fwrite($fp, ''); | |
fclose($fp); | |
} | |
$result = file_put_contents(XUP_FILE_XLS, file_get_contents($url)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment