Reputation: 205
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);
Upvotes: 0
Views: 8723
Reputation: 723598
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:
$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.
Upvotes: 4
Reputation: 57774
Does the destination path /home/pramiro/public_html/new/images/memo/
really exist? The error suggests it does not.
Upvotes: 0
Reputation: 20721
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.
Upvotes: 3