我正在尝试使用.cmd文件和.php文件将文件移动到旧文件夹时重命名文件。此文件正在批处理作业中通过电子邮件发送,然后移动到报告结束时的上一个月和当前年份的旧文件夹中。现在:文件正在正确的电子邮件,并移动到旧的文件夹,但文件名不输入旧文件夹时重命名。任何人都可以对我的代码提出任何建议?我似乎找不到错误在哪里。感谢
I'm trying to rename a file while it is being moved into an "old" folder using a .cmd file and a .php file. This file is being e-mailed in a batch job and then moved into the old folder with the previous month and current year at the end of the report. Right now: The files are being e-mail correctly, and moved into the old folder, however the file name is not being renamed when it enters the "old" folder. Can anyone make any suggestions to my code? I can't seem to find out where the error is. Thanks
我的代码为.CMD文件:
My code for .CMD file:
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文件的代码:
My code for .PHP file:
/*This application pickups up *.csv files from Monthly_Stats folder and then sends email to ops Support at ops.support@scotiabank. 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"; // $email_to = "ops.support@yahoo"; $email_to = "k.j@yahoo,g.h@yahoo"; $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); }推荐答案
c> rename 函数,您需要(A)转义反斜杠( \\ ),或者目录分隔符
In your rename function, you need to either (A) escape your backslashes (\\), or (B) use forward slashes for directory separators
更多推荐
移动后重命名文件
发布评论