PHP重命名函数问题
我试图使用php重命名功能将服务器上的文件从一个文件夹移动到另一个文件夹,但遇到了这个错误 警告:重命名(/home/pramiro/public_html/new/cipri/adauga/tmp/Koala.jpg,/home/pramiro/public_html/new/images/memo/Koala.jpg)[function.rename]:第13行的/home/pramiro/public_html/new/cipri/adauga/categie.php中没有这样的文件或目录 路径良好,文件夹存在,要复制的文件在tmp文件夹中。我可能做错了什么 代码如下:PHP重命名函数问题,php,Php,我试图使用php重命名功能将服务器上的文件从一个文件夹移动到另一个文件夹,但遇到了这个错误 警告:重命名(/home/pramiro/public_html/new/cipri/adauga/tmp/Koala.jpg,/home/pramiro/public_html/new/images/memo/Koala.jpg)[function.rename]:第13行的/home/pramiro/public_html/new/cipri/adauga/categie.php中没有这样的文件或目录
$filename=$_POST['poza_conv'];
$filename=substr($filename,37);
$old_path='/home/pramiro/public_html/new/cipri/adauga/tmp/'.$filename;
$new_path=' /home/pramiro/public_html/new/images/';
switch($_POST['categorie_conv'])
{
case 'memo': $filename=$new_path.'memo/'.$filename;
break;
case 'ort_sup': $filename=$new_path.'ort_sup/'.$filename;
break;
}
rename($old_path,$filename);
也许吧?PHP脚本可能不在您自己的用户帐户下运行,如果PHP用户没有读取文件的权限,PHP将看不到这些文件。目标路径
/home/pramiro/public\u html/new/images/memo/
真的存在吗?错误表明它不存在。这是您的错误:
$new_path=' /home/pramiro/public_html/new/images/';
在/home
前面有一个前导空格,它导致了错误,因此应该是:
$new_path='/home/pramiro/public_html/new/images/';
如果仍然出现错误,那么下一个最有可能的罪魁祸首是权限,正如其他人所说,尤其是在您移动文件的目录上的权限,以及文件本身。请显示您正在使用的代码。那么我应该使用什么权限?您应该将文件chmod到777PHP或图像?或者两者都使用?如果有的话,图像。然而,一个更好的解决方案,尤其是在共享主机上,是让PHP用户(
www-data
对于一个典型的LAMPP-box)访问它们,或者通过一个组,或者让它成为所有者。它是存在的!甚至尝试了echo getcwd()@Vidi:您应该使用is\u dir($new\u path)进行检查代码>而不是getcwd()代码>。