file management

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
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

file management

Post by jaylin »

Dear Experts,

now i have a problem that is -
it is possible to copy a file (image) from one folder to any folder without any upload? that will be done in the server.

is there any way to do that?
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

this works fine if the folder is in the same level.
in my case,
-currentfolder
- a.jpg
-movedfolder
-filefolder
- index.php
- change.php
i have the copy() function in the chage.php which is in the filefolder. i want to copy a.jpg from currentfolder to movedfolder as b.jpg

how can i do that?
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Put the path to the second folder plus the new filename as the second argument.
User avatar
sp2hari
Forum Newbie
Posts: 14
Joined: Fri Jan 13, 2006 3:54 am

this is working

Post by sp2hari »

Code: Select all

copy("a.jpg","../movedfolder/b.jpg");
will work
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

i have 3 folders (old, new, file). i want to move a file from old folder to new folder. my php file is in the file folder.
for say, i want to move 1.jpg from old folder to new as file name 2.jpg

can u give me the code? as i m very urgent and i can't fix it myself.

regards,
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

How many ways do we have to explain this? We have given you the code.
User avatar
sp2hari
Forum Newbie
Posts: 14
Joined: Fri Jan 13, 2006 3:54 am

Absolute path

Post by sp2hari »

hi,
try giving absolute path
if you are working in a linux server
then give this

Code: Select all

copy("/var/www/html/old/a.jpg"."/var/www/html/new/b.jpg");
Else
try using chdir () function to change your current working directory and then copy :)
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

You can also use the $_SERVER['document_root'] to work out the absolute path for your folders. Your folder must have the correct permissions as well.

EDIT
This should help you:
viewtopic.php?t=37902

As you can see I have been in your postition once before :)
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

Post by jaylin »

the pic can't be seen although i found the file through my ftp.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

use realpath() to translate relative path to absolute (if it exits)
Post Reply