【问题标题】:How to check Image name in folder and rename it?如何检查文件夹中的图像名称并重命名?
【发布时间】:2016-06-08 08:54:30
【问题描述】:

我有一个带有图像名称和图像前缀的 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

请帮助我找到解决方案。

【问题讨论】:

    标签: php file csv


    【解决方案1】:
    <?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.
        }
      }
    ?>
    

    试试这个,照顾我的 cmets。 ;)

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      相关资源
      最近更新 更多