2016-06-08 94 views
0

我有一個csv文件,圖像名稱和圖像前綴,我想在該圖像名稱中添加前綴,並將其重命名並將其移動到另一個目錄。如何檢查文件夾中的圖像名稱並重命名它?

<?php 


$fullpath = '/var/www/html/john/Source/01-00228.jpg'; 
$additional = '3D_Perception_'; 

while (file_exists($fullpath)) { 
    $info = pathinfo($fullpath); 
    $fullpath = $info['dirname'] . '/' . $additional 
       . $info['filename'] 
     . '.' . $info['extension']; 
echo $fullpath ; 
} 

?> 

下面的圖像文件儲存在Source目錄我想將它與一些前綴重命名和移動它其他目錄一樣Destination

請幫我找到這個解決方案。

回答

0
<?php 
    $source_directory = '/var/www/html/john/Source/'; 
    $dest_directory = '/var/www/html/john/Source/'; // Assuming you'll change it 
    $filename = '01-00228.jpg'; 
    $prefix = '3D_Perception_'; 

    $file = $source_directory . $filename; 
    $dest_file = $dest_directory . $prefix . $filename; 

    if (file_exists($file)) { 
    if (copy($file, $dest_file)) { 
     unlink($file); // Deleting source file. 

     var_dump(pathinfo($dest_file)); // Dump dest file infos, replace it with wathever you want to do. 
    } else { 
     // if copy doesn't work, do something. 
    } 
    } 
?> 

試試這個,並注意我的意見。 ;)