Page 1 of 1
Copying files
Posted: Thu Apr 12, 2007 8:49 am
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?

Posted: Thu Apr 12, 2007 8:54 am
by feyd
Why not use
copy() instead of attempting to use an operating system specific copy command?
Posted: Thu Apr 12, 2007 9:10 am
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.
Posted: Thu Apr 12, 2007 9:13 am
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"
Posted: Thu Apr 12, 2007 10:03 am
by ChessclubFriend
works great! Thanks