rename() erro

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

rename() erro

Post by pelegk2 »

i have tried to rename a filelike this:

Code: Select all

rename("files/0421045_01.txt","files/backup/0421045_01.txt")
and it didnt work(and i have permmisions for these folder)
the fles folder is a flder in the folder where my scripts run's
and the backup folder is inside the files folder!
when i also try

Code: Select all

rename("/files/0421045_01.txt","/files/backup/0421045_01.txt")
i still get the medssage
no such file or directory!
what to do?
thanks in advance
peleg
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

uh.. you're renaming a file to a different folder. :?:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

try this

Code: Select all

rename($_SERVER['DOCUMENT_ROOT']."/files/0421045_01.txt",$_SERVER['DOCUMENT_ROOT']."/files/backup/0421045_01.txt")
does the backup folder exist?

Mark
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

doesn't make a ton of sense that renaming ascross differing folders works, sorta.. but ok..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

feyd wrote:doesn't make a ton of sense that renaming ascross differing folders works, sorta.. but ok..
Well, the isn't a move funtion, so this is an alternative
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

Bech100 2 things :
first your code is ok
second how do i get the shortname of : "C:\Program Files"
third : yes its alternative for the move function:)

and feyd what there isnt a sence in it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

forget it.. "C:\progra~1" is the short name..
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

feyd : forget it????????????????????????????????/
why is that?>
i know that the sort name
but there are cases like other folder that it will not always be ****~1
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

still isnt working

Post by pelegk2 »

Bech100
when i treid to do :

Code: Select all

$_SERVERї'DOCUMENT_ROOT']."/files/0421045_01.txt",
i got :

Code: Select all

"C:\\\\Program Files\\\\nusphere\\\\phpED\\\\/files/0421061_02.txt"
and when i tried to write manually the path to the file like this :

Code: Select all

rename("C:\\Program Files\\Apache Group\\Apache2\\htdocs\\uniprod\\files/0421061_02.txt","C:\\Program Files\\Apache Group\\Apache2\\htdocs\\uniprod\\files\\backup\\0421061_02.txt")
i still get the error :
that permmision denied! :
Warning: rename(C:\Progra~1\Apache~1\Apache2\htdocs\uniprod\files/0421061_02.txt,C:\Progra~1\Apache~1\Apache2\htdocs\uniprod\files\backup\0421061_02.txt): Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\uniprod\readFiles.php on line 30
OR
Warning: rename(C:\Program Files\Apache Group\Apache2\htdocs\uniprod\files/0421061_02.txt,C:\Program Files\Apache Group\Apache2\htdocs\uniprod\files\backup\0421061_02.txt): Permission denied in C:\Program Files\Apache Group\Apache2\htdocs\uniprod\readFiles.php on line 29
what to do?
thanks in advance
peleg
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

It has to do with Apache's permissions. You are (likely) only allowed to use paths stored in the conf.

The following might work. Note the single dot:

Code: Select all

rename("./foo.bar", "./backup/bar.foo");
./ means "current dir", so in other words, my index.php containing the above line is in the same directory as the foo.bar file. Might be of use?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

how do i add path's to the conf?
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

tried to sdo what u seggested still isnt working:(
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

You have the following structure of directories:
"/uniprod/readFiles.php"

Meaning, you are in the uniprod directory when calling the script. We call this directory '.'

You have a file you want to move in a sub-directoty called files. Slap those together and we have:
"./Files/"

So perhaps you want:

Code: Select all

rename("./files/0421045_01.txt","./files/backup/0421045_01.txt")
Post Reply