亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 2019 | 回復: 1
打印 上一主題 下一主題

用PHP寫了個校園里賣二手書和二手物品的小網站 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-03-06 10:50 |只看該作者 |倒序瀏覽
用PHP寫了個校園里賣二手書和二手物品的小網站





我在做CS1010(Programming Methodology)的Tutor,其中一個任務是給學生作業(yè)判分,然后把判分的結果發(fā)給學生。



學生作業(yè)在我電腦里面folder的結構是:題號->學生學號->題目;其中題目為C code,有時候有其它的Tutor用Word判分之后會把結果發(fā)給我。



為了保護學生隱私,我需要分別給每個學生發(fā)送他的成績,附上他的批改過的作業(yè)作為附件。于是,我可以用電腦來做這個重復而且麻煩的事情。



這里用的是PHP,以及它的Pear組件中的Pear_mail (用來發(fā)送email),和pear_mime(用來給email加入附件)。學生的email就是學生學號@學校網址。



code見下(這里居然不能用PHP后綴作為附件!應該是因為怕上傳上去自動執(zhí)行PHP吧~)。我覺得這是一次很好的Programming Practice——把一些編程技巧拿來解決實際問題。





Php代碼
  1. <?php   
  2. // basic email settings   
  3. require_once "Mail.php";   
  4. require_once "Mail/mime.php";   
  5. $params = array(   
  6.     'host' => "ssl://smtp.gmail.com",   
  7.     'port' => "465",   
  8.     'auth' => true,   
  9.     'username'   => "something@gmail.com", // CONFIG your username comes here   
  10.     'password'   => "Your Password", // CONFIG and your password   
  11. );   
  12. $from = "something@gmail.com";     // CONFIG your email address   
  13. $cc = "something@gmail.com";    // CONFIG the cc address    -- put your address so that you can confirm that the email has been sent successfully   
  14. $subject = "[CS1010] PE Mark";   
  15. $body =                         // CONFIG: the message you want to pass to your student, it's in the HTML format   
  16.     "<p>Please Check the attachment(the word file) for your PE1 Mark. I didn't mark your PE but the graders are following the same scheme. If you have any problem with it, please email me.</p></br><p>Regards, </p> <p>Your Name</p>";   
  17.   
  18. // Generate the location array   
  19. $markLoc = "../PE_DG4";     // CONFIG: the file location of the folder storing ex1, ex2, ...   
  20.   
  21. $regEx = "/^ex\\d$/";   
  22. $regMatrix = "/^[au]\\d+$/";   
  23. $regWord = "/\\.docx$/";   
  24. $regCProg = "/\\.c$/";   
  25.   
  26. // location str:   
  27. $loc = array();   
  28.   
  29. $fileNameArr = array($markLoc);   
  30. foreach(scandir($markLoc) as $exName){   
  31.     if(!preg_match($regEx,$exName)) continue;   
  32.     array_push($fileNameArr,$exName);   
  33.     foreach(scandir(implode("/",$fileNameArr)) as $matrixNum){   
  34.         if(!preg_match($regMatrix,$matrixNum))  continue;   
  35.         if(!array_key_exists($matrixNum,$loc))  $loc[$matrixNum] = array();   
  36.         array_push($fileNameArr,$matrixNum);   
  37.         foreach(scandir(implode("/",$fileNameArr)) as $file){   
  38.             if(preg_match($regWord,$file)){   
  39.                 array_push($fileNameArr,$file);   
  40.                 $loc[$matrixNum][] = implode("/",$fileNameArr);   
  41.                 array_pop($fileNameArr);   
  42.             } else if(preg_match($regCProg,$file)){   
  43.                 array_push($fileNameArr,$file);   
  44.                 $loc[$matrixNum][] = implode("/",$fileNameArr);   
  45.                 array_pop($fileNameArr);   
  46.             }   
  47.         }   
  48.         array_pop($fileNameArr);   
  49.     }   
  50.     array_pop($fileNameArr);   
  51. }   
  52.   
  53. // then send out emails to each specific student   
  54.   
  55. foreach($loc as $matrix => $files){   
  56.     $message = new Mail_mime();   
  57.     $message->setHTMLBody($body);   
  58.   
  59.     // add in attachment here   
  60.     foreach($files as $file){   
  61.         $message->addAttachment($file);   
  62.     }   
  63.     $to = $matrix."@nus.edu.sg";   
  64.       
  65.     $headers = array(   
  66.         'From'  => $from,   
  67.         'Reply-to' => $from,   
  68.         'To'    => $to,   
  69.         'Cc'    => $cc,   
  70.         'Subject'   => $subject,   
  71.     );   
  72.   
  73.     $msgContent = $message->get();   
  74.     $msgHeader = $message->headers($headers);   
  75.   
  76.     $smtp = Mail::factory('smtp',$params);   
  77.     $mail = $smtp->send($to.",".$cc,$msgHeader,$msgContent);   
  78.   
  79.     if(PEAR::isError($mail)){   
  80.         echo "Error: ".$mail->getMessage()."\n";   
  81.     } else{   
  82.         echo "Message Sent Successfully to: $to\n";   
  83.     }   
  84. }   
  85.   
  86. ?>  
復制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2012-03-11 22:24 |只看該作者
謝謝分享
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP