解决wordpress在线安装插件主题的警告提示Warning: touch() [function.touch]: Utime failed: Result too large的方法

WordPress教程 1818

给某wordpress用户在后台安装插件时失败,提示:

Warning: touch() [function.touch]: Utime failed: Result too large in D:\wwwroot\wp-admin\includes\file.php on line 179

出现该问题是由于文件权限问题导致,在执行在线升级wp,在线安装主题、插件等等操作的时候默认情况下通常需要使用用系统临时目录(temp)暂存一些文件,对于使用vps或独立服务器的站长可以直接通过设置相应临时目录的权限来解决这个问题,而使用虚拟主机的站长,可以创建一个temp目录,并设置目录权限为可写。

看wp-includes/functions.php 文件中的get_temp_dir函数,这个函数是wp用来获取系统临时目录的方法,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function get_temp_dir() {
static $temp;
if ( defined('WP_TEMP_DIR') )
return trailingslashit(WP_TEMP_DIR);
if ( $temp )
return trailingslashit( rtrim( $temp, '\\' ) );
if ( function_exists('sys_get_temp_dir') ) {
$temp = sys_get_temp_dir();
if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
return trailingslashit( rtrim( $temp, '\\' ) );
}
$temp = ini_get('upload_tmp_dir');
if ( is_dir( $temp ) && wp_is_writable( $temp ) )
return trailingslashit( rtrim( $temp, '\\' ) );
$temp = WP_CONTENT_DIR . '/';
if ( is_dir( $temp ) && wp_is_writable( $temp ) )
return $temp;
$temp = '/tmp/';
return $temp;
}

通过看line 3 我们知道这个方法首先会寻找“WP_TEMP_DIR”常量是否定义过,如果这个常量定义过,则用这个常量定义的目录作为WP系统临时目录。

因此有了以下解决方法:

1、通过FTP创建临时目录 wp-content/temp,设置目录权限可读写。

2、wp-config.php文件中添加定义代码:

1
define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp');

方法摘自推酷,原博客已无法打开

精品推荐: