2015-03-03 72 views
1

IM產生從PHP腳本的每日報告下載特定文件(CSV),它位於一個文件夾中,如下所示如何使用PHP腳本

report_2015_02_15.csv 
report_2015_02_16.csv 
report_2015_02_17.csv 
report_2015_02_18.csv 
report_2015_02_19.csv 

和IM發送我的用戶鏈接的電子郵件下載時,一旦他們點擊下載鏈接,下載腳本觸發並準備下載。它目前將所有文件放到一個數組中並對其進行排序並找到最新的下載內容,

此方法在其中有一個流,即使您轉到舊的電子郵件2周並點擊下載鏈接,它會給你最新的報告,而不是給出兩週前的報告。

所以,有人可以告訴我一種方式發送我的電子郵件中的下載鏈接與其對應文件的關係嗎?

電子郵件的腳本

$down_link = Config_Reader::readProjectConfig('tad')->base_url.'CSVDownload.php; 

$mail = new Zend_Mail(); 
$sentFromEmail = $config->sentFromrec; 
$tr = new Zend_Mail_Transport_Sendmail ('-f' . $sentFromEmail); 
Zend_Mail::setDefaultTransport ($tr); 
$mail->setReturnPath($sentFromEmail); 
$mail->setFrom ($sentFromEmail, 'Reporting'); 

$email_body = "Hi,<br /><br />Download the weekly details of adtracker projects, by clicking the link below. 
<br /> <a href=".$down_link.">Report</a><br /><br />Thank You."; 

$mail->setBodyHtml ($email_body); 
$mail->addTo ($weeklyReportRec); 
$mail->setSubject ("Report"); 

try { 
     $mail->send(); 
    } catch (Exception $e) { 
     echo "Mail sending failed.\n"; 
    } 

下載腳本

$basePath = "$download/dailyReport/"; 
$csvFiles = glob($basePath."/*.csv"); 
if(count($csvFiles)){ 
    array_multisort($csvFiles, SORT_DESC); 
    $csvFile = $csvFiles[0]; 
}else{ 
    exit("Server error!"); 
} 

$h = fopen($csvFile, "r"); 
$contents = fread($h, filesize($csvFile)); 
+0

向包含報告日期的URL添加一個參數,並在下載腳本中使用該參數,而不是僅返回最新的參數。 – Barmar 2015-03-03 06:28:22

+0

我用它..人們說它不安全!這可能會對我的服務器造成注入攻擊 – 2015-03-03 06:30:49

+0

檢查參數的格式,確保它只是日期,沒有別的。 – Barmar 2015-03-03 06:39:42

回答

0

您可以使用指示下載鏈接報告日期的查詢參數。 .../CSCDownload.php?date = 2015/02/17

這將允許您從可用列表中選擇相應的報告。

+0

我用它..人們說它不安全!這可能會對我的服務器造成注入攻擊 – 2015-03-03 06:31:30

+0

您不存儲在查詢參數中發送的信息或將它存儲在任何地方。你只是用它來解決報告。所以我不明白這會如何導致注入攻擊。 – Akhilesh 2015-03-03 06:35:01

+0

好吧然後等待虐待嘗試..謝謝你的回覆 – 2015-03-03 06:41:02

0

你可以使用類似的東西作爲下載腳本。我做只是minum變化得到它的工作:

$date = $_GET['date']; 
$basePath = "$download/dailyReport/"; 
$csvFiles = glob($basePath."/*.csv"); 

$file = $basePath . 'report_' . $date . '.csv'; 
$found = false; 

foreach($csvFiles as $csvFile){ 
    if($file === $csvFile){ 
     $found = $csvFile; 
     // You have found the file, so you can stop searching 
     break; 
    } 
} 
if(false === $found){ 
    exit("Server error!"); 
} 

$h = fopen($found, "r"); 
$contents = fread($h, filesize($found)); 

現在,你可以打電話給你的腳本與「example.com/getcsvfile.php?date=2015_02_15」你的瀏覽器,而不用擔心注射,因爲你檢查文件是csv文件之一。

+0

感謝您的答覆..虐待和讓我們knw – 2015-03-03 06:55:34