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
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
The paths are good, the folders exist and the file to be copied is in the tmp folder.What could I be doing wrong?
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:
There is a leading space just before
/home, which is causing the error, so it should be: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.