2012-04-27 191 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__)