简体   繁体   English

PHP重命名功能问题

[英]PHP rename function problem

I'm trying to move a file on my server from one folder to another using the php rename function, but I'm getting this error 我正在尝试使用php重命名功能将服务器上的文件从一个文件夹移动到另一个文件夹,但出现此错误

Warning: rename(/home/pramiro/public_html/new/cipri/adauga/tmp/Koala.jpg, /home/pramiro/public_html/new/images/memo/Koala.jpg) [function.rename]: No such file or directory in /home/pramiro/public_html/new/cipri/adauga/categorie.php on line 13 警告:重命名(/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/categorie.php中的目录

The paths are good, the folders exist and the file to be copied is in the tmp folder.What could I be doing wrong? 路径很好,文件夹存在并且要复制的文件在tmp文件夹中。我怎么可能做错了?

This is the code: 这是代码:

$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);

Here's your mistake: 这是您的错误:

$new_path=' /home/pramiro/public_html/new/images/';

There is a leading space just before /home , which is causing the error, so it should be: /home之前有一个前导空格,这会导致错误,因此应该是:

$new_path='/home/pramiro/public_html/new/images/';

If you still get the error, then the next most likely culprit is, as others say, permissions, particularly on the directories you are moving the file between, and the file itself. 如果仍然出现该错误,那么就像其他人所说的那样,下一个最可能的罪魁祸首是权限,尤其是在您要在其间移动文件的目录以及文件本身上。

Permissions maybe? 权限可能? The PHP script probably doesn't run under your own user account, and if the PHP user doesn't have permission to read the files, PHP won't see them. PHP脚本可能不在您自己的用户帐户下运行,并且如果PHP用户没有读取文件的权限,PHP将看不到它们。

Does the destination path /home/pramiro/public_html/new/images/memo/ really exist? 目标路径/home/pramiro/public_html/new/images/memo/确实存在? The error suggests it does not. 该错误表明事实并非如此。

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

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