在将批处理作业电子邮件发送到“OLD”文件夹后,我正在尝试移动文件。
我已经成功地确定了这样做的代码。现在该文件被称为monthly_mssql
,我正在尝试将文件重命名为monthly_mssql_mmmyyyy
.
在文件末尾添加月份和年份后,我可以跟踪确定哪些报告是针对哪个月份的。我将如何编辑现有的命令文件?
我的 CMD 文件代码:
REM The report is generated automatically and must be sent at 9:50 AM of the first Monday of every month, file is located
REM in C:\Reports\mssql\Monthly_Stats
"C:\Program Files\xampp\php\php.exe" "c:\htdocs\MultipleReport\monthly_smurfreport_email.php"
move C:\Smurf_Reports\mssql\Monthly_Stats\monthly_mssql.csv C:\Smurf_Reports\mssql\Monthly_Stats\old
我的 PHP 文件代码:
$dirpath = "C:/Reports/mssql/Monthly_Stats/";
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 = "k.j@yahoo.com";
// $email_to = "kj@yahoo.com"; $email_to = "kj@yahoo.com";
$lastMonth = date('F-Y',strtotime('last month'));
$email_subject = "($lastMonth) Report for MS-SQL.";
$headers .= "From: ".$email_from."\r\n";
echo $filepath."</br>";
}
}
closedir($handle);
$ok = @mail($email_to, $email_subject, $email_message, $headers);
}
/*if (file_exists($filename) && $size > 228 && $EmailAdd <> "")
{
$fileatt = $filename;
$fileatt_name = $groupname.".csv";
if ($uemail <> "")
$email_from = $uemail;
else
$email_from = $username."@yahoo.com";
$email_to = $email_from;
$email_subject = " Messages for Priority '".$p."' - ".$groupname." - ".$displaydate;
$headers .= "From: ".$email_from. "\r\n";
$headers .= "Cc: ".$EmailAdd. "\r\n";
$headers .= "Bcc: k.j@yahoo.com";
$email_message .= "<P>Hi</P>";
$email_message .= "<P><B>Please find attached Monthly Smurf Report Stats."</U></B>\n";
$email_message .= "<P><P>Thanks,<P>;
set_error_handler("myErrorHandler");
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if ($ok)
{
unlink($filename);
}
else
{
$file = "C:/Reports/Operation/Daily_Stats/smtperrlog.txt";
$fh = fopen($file, 'r+');
$contents = fread($fh, filesize($file));
fclose($fh);
$stderr = fopen ('C:/Reports/Operation/Daily_Stats/smtperrlog.txt', 'w+');
fwrite($stderr,"");
fclose($stderr);
$email_fromerr = "k.j@yahoo.com";
$email_toerr = "k.j@yahoo.com";
$email_subjecterr = "Monthly Stats";
$email_messageerr = $contents;
$headerserr .= "From: ".$email_fromerr. "\r\n";
@mail($email_toerr, $email_subjecterr, $email_messageerr, $headerserr);
}
}
*/
$message_text = "";
$p = "";
$EmailAdd = "";
$headers = "";
$counter = 0;