2

i use the following code to move image one folder to another folder but it does not work.

as follows

if(file_exists('admin/passenger_photo/p1.jpg'))
{
    rename('admin/passenger_photo/p1.jpg' , 'admin/driver_photo/p1.jpg');
    echo "success";
} 

but yet it does not work. thanks & regards

iatboy
  • 1,295
  • 1
  • 12
  • 19
san san
  • 118
  • 2
  • 13
  • 2
    Are you getting an error? – Jonan Aug 28 '14 at 08:30
  • 3
    Have you checked your script's permissions for reading and writing from and to the respective directories? – fuesika Aug 28 '14 at 08:30
  • possible duplicate of [PHP - Move a file into a different folder on the server](http://stackoverflow.com/questions/19139434/php-move-a-file-into-a-different-folder-on-the-server) – 웃웃웃웃웃 Aug 28 '14 at 08:30
  • `file_exists` requires full base path of the file, so as `rename` to rename it..try giving full path to both functions and it will work like a charm.. – Coder anonymous Aug 28 '14 at 08:33
  • `http://php.net/manual/en/function.file-exists.php`.. – Coder anonymous Aug 28 '14 at 08:34
  • by full path i got error Warning: rename(localhost/chauffers/admin/passenger_photo/p1.jpg,localhost/chauffers/admin/driver_photo/p1.jpg) [function.rename]: No error in C:\wamp\www\chauffers\passenger_user.php on line 252 – san san Aug 28 '14 at 08:36
  • 1
    @user3342546 it's not absolute path, you must use real file system path, not url. Something like file_exists('/var/www/html/chauffers/admin/passenger_photo/p1.jpg') – Nebojsa Susic Aug 28 '14 at 08:42
  • if i used like this rename('http://localhost/chauffers/admin/passenger_photo/p1.jpg' , 'http://localhost/chauffers/admin/driver_photo/p1.jpg'); i get error Warning: rename() [function.rename]: http wrapper does not support renaming in C:\wamp\www\chauffers\passenger_user.php on line 251 – san san Aug 28 '14 at 08:46

1 Answers1

4

The script works fine in my lab. Possible check the permission environment and file permission.

SonDang
  • 1,468
  • 1
  • 15
  • 21