Moving files
Moderator: General Moderators
- moiseszaragoza
- Forum Commoner
- Posts: 87
- Joined: Sun Oct 03, 2004 4:04 pm
- Location: Ft lauderdale
- Contact:
Moving files
Hey every one I have been wandering if anyone knows the function to move a file to another directory
Thanks
Thanks
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Just like you use `mv' in UNIX to "move" files (aka, rename files) you use the function rename()
http://www.php.net/rename

http://www.php.net/rename
- moiseszaragoza
- Forum Commoner
- Posts: 87
- Joined: Sun Oct 03, 2004 4:04 pm
- Location: Ft lauderdale
- Contact:
- moiseszaragoza
- Forum Commoner
- Posts: 87
- Joined: Sun Oct 03, 2004 4:04 pm
- Location: Ft lauderdale
- Contact:
by any chance can a directory name contain the ../ or do it has to be a absolute path
error im getting when using rename()
code
error im getting when using rename()
Code: Select all
Warning: rename(../../../imagesSmall/DSCN1148.jpg,/imageDone/DSCN1148.jpg): No such file or directory in /home/content/m/o/i/moiseszaragoza/html/sites/Stockimages/backend/protectedArea/AddImage/moveImage.php on line 92Code: Select all
$dir = "../../../imagesSmall/";
$ImageName=$_GET['ImageName'];
echo("<img src='$dir$ImageName'>"); // this works i do see a image
rename("$dir$ImageName", "/imageDone/$ImageName");// this is line 92well there's two rules when renaming files
the source file must exist and be readable by apache
the destination *"folder"* must exist
if you have /root/file
and you want to rename it to
/root/folder/folder2/file
you must first mkdir('/root/folder/') and mkdir('/root/folder/2'), BEFORE renaming the original
or use this function I found in the comments on the manual (untested)
the source file must exist and be readable by apache
the destination *"folder"* must exist
if you have /root/file
and you want to rename it to
/root/folder/folder2/file
you must first mkdir('/root/folder/') and mkdir('/root/folder/2'), BEFORE renaming the original
or use this function I found in the comments on the manual (untested)
Code: Select all
function mkdir_recursive($dirName){
foreach(split('/',dirname($dirName)) as $dirPart)mkdir($newDir="$newDir$dirPart/");
}
mkdir('/root/folder/folder2/')
rename('/root/file', '/root/folder/folder2/file');- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Your not mistaken...timvw wrote:If i'm not mistaken the unix command mkdir -p (or mkdirhier) does this for you too
The -p flag indicates that UNIX/Linux should attempt to create the path for you if it doesn't exist.
As for rename() I'm alomst certain the path must exist.... we're programmers... not desktop users