Copying files

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
ChessclubFriend
Forum Newbie
Posts: 21
Joined: Sun Mar 25, 2007 9:13 pm

Copying files

Post by ChessclubFriend »

Code: Select all

if($votetopic)
 {
$directoryname = $votetopic;
chdir('Topics');

if(!(file_exists($votetopic)))
{
$directorymaker = "$votetopic";
mkdir($directorymaker, 0777);
exec('cp *.txt $votetopic');
chdir('..');}
}
This checks if there is a votetopic, then changes to the Topics directory. If votetopic doesn't exist as a directory inside Topics yet, it is created. Then I want to copy all txt files inside the Topics directory to the votetopic directory, but no matter how I try to use the copy command it won't copy the text files.

my directory structure looks like this:
http://www.chessclubfriend/Topics/$votetopic

How can I copy these files? :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why not use copy() instead of attempting to use an operating system specific copy command?
ChessclubFriend
Forum Newbie
Posts: 21
Joined: Sun Mar 25, 2007 9:13 pm

Post by ChessclubFriend »

well, when I set votetopic to 44 and tried the following it said:

Warning: copy(/44/votesyay.txt): failed to open stream: No such file or directory in /home/content/C/h/e/ChessFriend/html/VoteForm.php on line 70

Code: Select all

$file = "votesyay.txt"
$newfile = "/$votetopic/votesyay.txt";
copy($file, $newfile);

so I'm having trouble getting cp or copy working actually.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

/44 would be a folder in the root, not in your directory structure. That's why copy() fails.

You want to use "/home/content/C/h/e/ChessFriend/html/44/votesyay.txt"
ChessclubFriend
Forum Newbie
Posts: 21
Joined: Sun Mar 25, 2007 9:13 pm

Post by ChessclubFriend »

works great! Thanks
Post Reply