简体   繁体   中英

PHP rename() file_exists()

How can I use PHP to move a file?

Code:

if( file_exists($imageLocation) )
  echo "file exists on server";

rename($imageLocation, $imageNewLocation);

Output:

file exists on server Warning: rename(/home/images/file1.jpg,/home/newloc/renamed.jpg) [function.rename]: No such file or directory in /home/apps/images/add.php on line 81

I don't know where to go from here.

When moving files, rename() can only move them to a folder that already exists. It can not create new parent directories on the fly.

Make sure /home/newloc exists. If it doesn't, use mkdir() to create it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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