[英]PHP rename() does not find file with space in filename
I'm using PHP rename() function to move a file. 我正在使用PHP named()函数移动文件。 The file has space in the filename though. 但是文件名中有空格。 And for some reason it can't find it. 由于某种原因,它找不到它。 I tried escaping it but that didn't work either. 我尝试将其转义,但这也不起作用。 Does someone have an idea what is going on? 有人知道发生了什么吗? It is on a Unix system. 它在Unix系统上。
$filename = basename($file->uri);
// Tried this once didn't work either:
$filename = str_replace(' ', "\ ", $filename);
//
rename($_SERVER['DOCUMENT_ROOT'].$source.'/'.$filename,
drupal_realpath($file->uri));
Thank you very much in advance. 提前非常感谢您。
I don't think it's space issue. 我不认为这是空间问题。 Probably simple your file doesn't exist in the path you give to rename function. 您提供的重命名功能路径中可能不存在您的文件,可能很简单。
Try to display the path: 尝试显示路径:
echo $_SERVER['DOCUMENT_ROOT'].$source.'/'.$filename;
and make sure this path is really valid in your case 并确保此路径在您的情况下确实有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.