Php 尝试使用filemtime添加版本控制,但失败

Php 尝试使用filemtime添加版本控制,但失败,php,wordpress,versioning,filemtime,Php,Wordpress,Versioning,Filemtime,在wordpress环境中 我正在尝试使用filemtime自动向脚本添加版本控制,但收到以下错误消息: Warning: filemtime() [function.filemtime]: stat failed for (file name) 代码很简单 $myfile = get_template_directory_uri() . '/js/script.js'; wp_enqueue_script('mywebsite-script',$myfile , array( 'jquery

在wordpress环境中

我正在尝试使用
filemtime
自动向脚本添加版本控制,但收到以下错误消息:

Warning: filemtime() [function.filemtime]: stat failed for (file name)
代码很简单

$myfile = get_template_directory_uri() . '/js/script.js';
wp_enqueue_script('mywebsite-script',$myfile , array( 'jquery' ), filemtime( $myfile ), true );
文件的路径是正确的,但正如我所说的,我得到了
statfailed
消息

如果我添加
If(file\u exists($myfile))
检查,则跳过整个操作。 但是,如果我回显到
$myfile
的路径,这是正确打印的,可以在浏览器中打开

路径不包含花式字符。服务器不在Windows上,我读过编码可能是原因之一,但不知道解决方法应该是什么,如果是这样的话


问题出在哪里?

您应该使用实际路径:

$myfile = get_template_directory_uri() . '/js/script.js';
$realpath = get_template_directory().'/js/script.js';
wp_enqueue_script('mywebsite-script',$myfile , array( 'jquery' ), filemtime( $realpath ), true );

您应该改用实际路径:

$myfile = get_template_directory_uri() . '/js/script.js';
$realpath = get_template_directory().'/js/script.js';
wp_enqueue_script('mywebsite-script',$myfile , array( 'jquery' ), filemtime( $realpath ), true );

文件权限。。。这是我的想法,php是否有权限访问该文件。@ArtisticPhoenix:但php可以读取该文件,通过Wordpress将脚本排队。。。难道它不能同时读取文件吗?你知道有没有办法通过php检查这是否是权限问题?文件权限。。。这是我的想法,php是否有权限访问该文件。@ArtisticPhoenix:但php可以读取该文件,通过Wordpress将脚本排队。。。难道它不能同时读取文件吗?你知道有没有办法通过php检查这是否是一个权限问题吗?我原以为这也失败了,但我错了,我在评论部分时搞砸了。这起作用了。谢谢有趣的是,我使用
\uURI
Wordpress的东西找到了一些例子。我刚刚发现这在我的xampp上是局部中断的。脚本的“真实路径”现在看起来像:
http://localhost/folderD:foldersonhardiskwithnospaces/wp-content/themes/theme/js/script.js
…get_template_directory()将返回一个实际路径,例如:/var/www/wordpress/wp.local/wp-content/themes/twenty17(linux)。我看到您提供的是一个“uri”而不是“目录路径”。我错了吗?是的,我在
filemtime
中需要它,但在
wp\u enqueue\u脚本中不需要它。现在,正如我所描述的,我已经将两者分开,回答了我自己的问题。我认为这也失败了,但我错了,我在评论部分时把事情搞砸了。这起作用了。谢谢有趣的是,我使用
\uURI
Wordpress的东西找到了一些例子。我刚刚发现这在我的xampp上是局部中断的。脚本的“真实路径”现在看起来像:
http://localhost/folderD:foldersonhardiskwithnospaces/wp-content/themes/theme/js/script.js
…get_template_directory()将返回一个实际路径,例如:/var/www/wordpress/wp.local/wp-content/themes/twenty17(linux)。我看到您提供的是一个“uri”而不是“目录路径”。我错了吗?是的,我在
filemtime
中需要它,但在
wp\u enqueue\u脚本中不需要它。现在,正如我所描述的,我已经将两者分开,回答了我自己的问题。