2015-02-23 4 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

Смежные вопросы