2012-04-27 260 views
0

我的PHP知識是有限的,我試圖將http://www.tutorialchip.com/php-download-file-script/這個腳本實現到我的網站。我已經在這裏推出了他們的文件http://brooksmemories.com/test/。如果點擊一個文件,我得到了以下錯誤用PHP強制下載文件

Strict Standards: main() [function.main]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead in /home/inspire/public_html/brooksmemories.com/test/download.php on line 16

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /home/inspire/public_html/brooksmemories.com/test/download.php on line 16

我不知道如何糾正這些錯誤得到它的工作。任何幫助將不勝感激。謝謝。

+0

PHP中不存在'__DIR__'常量<= 5.2;在其位置使用'dirname(__ FILE __)'。時區警告[由Google解釋](http://www.google.de/search?q=Strict+Standards:+main()+%5Bfunction.main%5D:+ It + is + not + safe +到+靠+上+的+系統+時區+設置。+請+使用+的+ date.timezone +設置+的+ TZ +環境+變量+或+的+ date_default_timezone_set()+功能)。 – mario 2012-04-27 17:32:39

+0

@mario:據我所知,時區警告是由此通知引起的。出於某種原因,即使錯誤也會導致PHP中的錯誤。奇怪,但這是它的工作原理。我會修改配置,所以這個警告不會發生,但在這種情況下,它根本就沒有任何意義。 – xfix 2012-04-27 17:36:19

回答

1

檢查你的PHP版本... __DIR__是一個新的常數僅在PHP 5.3+的方式來達到同樣在舊版本的PHP是用:代替__DIR__

的時區dirname(__FILE__)消息可以固定在php.ini的條目:

;approx line 1005 
[Date] 
date.timezone = "America/Chicago"; 

或通過添加date_default_timezone_set到PHP文件的頂部:

<?php 
date_default_timezone_set('America/Chicago'); 
//... 
+0

這樣做。升級並添加了該行代碼。非常感謝你。 – 2012-04-27 17:43:16

0

第一個警告是關於使用某個日期函數。在這種情況下,我認爲警告本身會激活它(它將它存儲在日誌中)。服務器警告更重要,它提到了未定義魔術常數__DIR__(當前腳本目錄)的使用。它是在PHP 5.3中引入的。

所以,你有兩個選擇。

  1. 更新到PHP 5.3 5.4
  2. 更換__DIR__dirname(__FILE__)