Wei, Alice J. wrote:
Hi,
I have a scenario here where I wanted to read through a directory and copy all the files into another directory out on the server somewhere.
It appears that I cannot do reiterative copying from the files to another folder, according to the error I keep seeing:
PHP Warning: copy(a2.txt): failed to open stream: No such file or directory in /home/ajwei//Desktop/file_copy.php on line 18
Error! Couldn't copy a2.txt to /home/ajwei/Documents/test1/a2.txt
Is it possible that there is an alternative for this? I have no problems with reading through the directory using readdir(),
<?
if ($handle = opendir('/home/ajwei/Desktop/test/')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
mkdir("/home/ajweiDocuments/test1", 0755);
while (false !== ($file = readdir($handle))) {
echo "$file\n";
$result= copy($file, '/home/ajwei/Documents/test1/$file');
if ($result) {
echo "$file has been copied to /home/ajwei/Documents/test1/$file\n\n";
}
else {
echo "Error! Couldn't copy $file to /home/ajwei/Documents/test1/$file\n";
}
}
}
closedir($handle);
Is there an alternative to what I am meant to do if the copy() cannot be functioned the way I anticipated?
I welcome any suggestion.
Alice
======================================================
Alice Wei
MIS 2009
School of Library and Information Science
Indiana University Bloomington
ajwei@xxxxxxxxxxx
#1 you have singles instead of doubles around this:
'/home/ajwei/Documents/test1/$file' so $file is not interpreted.
#2 your not giving the path to the source file.
This should work:
$result= copy("/home/ajwei/Desktop/test/$file",
"/home/ajwei/Documents/test1/$file");
-Shawn
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php