我正在尝试重命名文件,同时使用 .cmd 文件和 .php 文件将其移动到“旧”文件夹中。该文件在批处理作业中通过电子邮件发送,然后在报告结束时将上个月和当年移动到旧文件夹中。现在:文件正在正确地通过电子邮件发送,并移动到旧文件夹中,但是当它进入“旧”文件夹时文件名没有被重命名。任何人都可以对我的代码提出任何建议吗?我似乎无法找出错误在哪里。谢谢
我的 .CMD 文件代码:
REM Email the 2 monthly stats files regarding gtwinapps
REM The report is sent at 9:20 AM every first monday of every month
REM in C:\Smurf_Reports\gtwinapps\Monthly_Stats
"c:\Program Files\xampp\php\php.exe" d:\batch\monthly_smurfreport_gtwinapps.php
move C:\Smurf_Reports\gtwinapps\Monthly_Stats\gtwinapps_statsmonthly.csv C:\Smurf_Reports\gtwinapps\Monthly_Stats\old
我的 .PHP 文件代码:
/*This application pickups up *.csv files from Monthly_Stats folder and then sends email to ops Support at ops.support@scotiabank.com.
The command file associated with this php file moves the .csv file into the "OLD" folder in the same directory
*/
$dirpath = "C:/Smurf_Reports/gtwinapps/Monthly_Stats/";
/* Renaming the batch job file to display the previous month and year once it is moved into the "OLD" folder for clarity purposes */
rename ("C:\Smurf_Reports\gtwinsapps\Monthly_Stats\gtwinapps_statsmonthly.csv", "C:\Smurf_Reports\ gtwinapps\Monthly_Stats\old\monthly_gtwinapps_" . date("F_Y", strtotime("-1 month")) . ".csv");
rename ("C:\Smurf_Reports\gtwinsapps\Monthly_Stats\monthly.csv", "C:\Smurf_Reports\gtwinapps\Month ly_Stats\old\gtwinapps_statsmonthly_" . date("F_Y", strtotime("-1 month")) . ".csv");
if ($handle = opendir($dirpath ))
{
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 8bit\n\n" .
$message_text . "\n\n";
$email_message .= "--{$mime_boundary}\n";
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle)))
{
if (strpos($entry, '.csv',1))
{
$filepath = "";
$filesize = 0;
$filepath = $dirpath."".$entry;
$filesize = filesize ($filepath);
if (file_exists($filepath) && $filesize > 1)
{
$fileatt = $filepath;
$fileatt_name = $entry;
$fileatt_type = "application/octet-stream";
$message_text .= "<P>Hi</P>";
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$data = chunk_split(base64_encode($data));
$email_message .= "Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
$email_message .= "--{$mime_boundary}\n";
}
$email_from = "ops.support@yahoo.com";
// $email_to = "ops.support@yahoo.com";
$email_to = "k.j@yahoo.com,g.h@yahoo.com";
$lastMonth = date('F-Y',strtotime('last month'));
$email_subject = "($lastMonth) Monthly Smurf Report for GTWINAPPS.";
$headers .= "From: ".$email_from."\r\n";
echo $filepath."</br>";
}
}
closedir($handle);
$ok = @mail($email_to, $email_subject, $email_message, $headers);
}