简体   繁体   English

在PHP的rename()函数中使用变量

[英]Using variables in rename() function PHP

I'm trying to use variables in PHP's rename() function but I must be doing it wrong as it's not working. 我正在尝试在PHP的rename()函数中使用变量,但是由于它无法正常工作,我必须做错了。

$save = 'myfile-wf.png'; // this filename is actually created dynamically but I've just written it here for clarity. The variable is tested and working.

rename("/var/www/$save", "/var/www/html/wave/$save");

But it's not happening. 但这没有发生。 Can you see what I'm doing wrong? 你能看到我做错了吗? Can I not use a variable in a filepath with rename()? 我不能在带有filename()的文件路径中使用变量吗?

The rename() function expects strings as parameters for paths: named()函数期望字符串作为路径的参数:

bool rename ( string $oldname , string $newname [, resource $context ] )

Strings don't have memory. 字符串没有内存。 Once you create one, PHP has no way to determine whether you created it using variables, reading data from a file or feeding it from a socket. 一旦创建了PHP,PHP将无法确定是使用变量,从文件读取数据还是从套接字提供数据来创建它。

Most likely reasons include: 最可能的原因包括:

  • Your strings do not contain what you think they do (as you've said, this is not actual code) 您的字符串不包含您认为的内容(如您所说,这不是实际的代码)

  • rename() is throwing a warning but you haven't configured your PHP development box to display (all) errors on screen. rename()发出警告,但您尚未配置PHP开发框以在屏幕上显示(所有)错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM