-1
How to rename a file after copying and pasting from one folder to another. It even renames, but only if I refresh the page, IE, I’m not able to process both functions at the same time.
Follow the code below:
<?php
include 'var.php';
// ### =============================== ###
// ### Converter nome dos arquivos ###
// ### =============================== ###
if($_mes <= '09'){ $_mes = substr($_data,6,1); } else { $_mes = substr($_data,5,2); }
if(isset($_data)){
if(is_dir($_In)){ /*echo $_In;*/
if(is_dir($mes_Out)){
$_g = glob("{$mes_Out}\*.pdf");
// var_dump($_g);
if(empty($_g)){ exec("xcopy ".$mes_In." ".$mes_Out);
} else { echo "Já existem arquivos nesse diretório.";}
foreach($_g as $files){
$fileName = substr($files, 43);
$n = substr($fileName, 0, 16).".pdf";
$_date = substr($n, 6, 16);
$_dt = str_replace('_','',$_date);
$_y = substr($_dt, 4, 4);
$_m = substr($_dt, 2, 2);
$_d = substr($_dt, 0, 2);
$_Mdt = $_y.$_m.$_d; // Monta Data
$dcm_hash = md5($n);
$length_Hash = substr($dcm_hash,0,8);
$_Fname = $_Mdt.$length_Hash.".pdf";
rename($files, $mes_Out.$_DS.$_Fname); // ### Renomeia arqs. do diretório de saída
set_time_limit(100000);
echo "Arquivos renomeados!"."<br>";
}
}
// ----------------------------------------------------------------------------------
}
}
?>