2015-02-23 52 views
0

我想將所有的.vtk文件和.raw文件移動到不同的文件夾。但它沒有被複制。我該如何解決?文件不復制到不同的文件夾

<?php 
define ('DOC_ROOT', $_SERVER['DOCUMENT_ROOT'].'/'); 
$src = '/var/www/html/php/'; 
$dest ='/var/www/html/php/emd/'; 
$dh = opendir ($src); //Get a directory handle 
$validExt = array('vtk','raw'); //Define a list of allowed file types 
$filesMoved = 0; 

// Loop through all the files in the directory checking them and moving them 
while (($file = readdir ($dh)) !== false) { 
    // Get the file type and convert to lower case so the array search always matches 
    $fileType = strtolower(pathinfo ($file, PATHINFO_EXTENSION)); 
    if(in_array ($fileType, $validExt)) { 
     // Move the file - if this is for the web really you should create a web safe file name 
     if (!$rename($src.$file, $dest.) { 
     echo "Failed to move {$file} to {$newPath}"; 
     } else { 
     echo "Moved {$file} to {$newPath}"; 
     $filesMoved++; 
     } 
    } 
} 
echo "{$filesMoved} files were moved"; 
closedir($dh); 
?> 

回答

1

你忘了添加文件名的目標,改變這一行:

if (!$rename($src.$file, $dest.) { 

到:

if (!$rename($src.$file, $dest.$file) { 

如果不工作,確保目標目錄確實存在並且您有寫入權限。如果您啓用了錯誤報告功能,您將看到如下錯誤消息:

Parse error: parse error in /path/to/script/rename.php on line 18

相關問題