Php 无法打开流:副本中的参数无效

Php 无法打开流:副本中的参数无效,php,copy,Php,Copy,我想从具有文件名的文件中读取文本,并想将这些文件复制到 另一个位置,不幸的是它不工作,如何解决这个问题?提前谢谢 //fetches the view file names to copy $handle = @fopen("D:/myfolder/log.txt", "r"); if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { // echo $buffer; $fil

我想从具有文件名的文件中读取文本,并想将这些文件复制到

另一个位置,不幸的是它不工作,如何解决这个问题?提前谢谢

//fetches the view file names to copy
$handle = @fopen("D:/myfolder/log.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        // echo $buffer;
        $filenames[] = $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}

foreach ($filenames as $row) {
    $fileNames  = explode("/", strval($row));
    $singleFile = "C:/wamp/www/project/application/modules/admin/" . strval($row);
    $file = $singleFile;  
    $newfile = "C:/Users/myname/Dropbox/local_changes/$fileNames[2]";
   //copy a file from one location to another
    if (!copy($file, $newfile)) {
        echo "failed to copy $file...\n";
    }
}
?>
log.txt的示例如下所示:

views/layouts/file1.phtml
views/layouts/file2.phtml

尽量使代码看起来更清晰。我试图提高代码的可读性。我猜读取源文件时会出现错误

<?php
//
// Setup.
//
$pathCopyInstructionsFile = 'D:/myfolder/log.txt';
$pathFilesSourceDirectory = 'C:/wamp/www/project/application/modules/admin/';
$pathFilesDestinationDirectory = 'C:/Users/myname/Dropbox/local_changes/';

//
// Execution.
// 

// Read copy instructions file (log).
if(!file_exists($pathCopyInstructionsFile)) {
    die('File "'. $pathCopyInstructionsFile .'" does not exist');
}
$filesToCopy = file($pathCopyInstructionsFile, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);

// Loop through $filesToCopy and try to copy them from $pathFilesSourceDirectory to $pathFilesDestinationDirectory.
foreach($filesToCopy as $fileToCopy) {
    // Set source file path and check if file exists - otherwise continue loop.
    $sourceFilepath = $pathFilesSourceDirectory . $fileToCopy;
    if(!file_exists($sourceFilepath)) {
        echo('Source file "'. $sourceFilepath .'" not found' . "\n");
        continue;
    }

    // Set destination file path. Only use filename itself for copying.
    $destinationFilepath = $pathFilesDestinationDirectory . basename($fileToCopy);

    // Try to copy.
    $successfulCopy = copy($sourceFilepath, $destinationFilepath);
    if(!$successfulCopy) {
        echo('Source file "'. $sourceFilepath .'" could not be copied to "'. $destinationFilepath . '"' . "\n");
    }
}
?>