复制&;将文件重命名到同一目录,而不删除原始文件


Copy & rename a file to the same directory without deleting the original file

可能重复:
使用PHP 克隆+重命名文件

这应该很容易。我不想复制&重命名服务器上已经存在的图像,同时保留原始图像

这是原始图像的位置:

images/
   folder/
       one.jpg

这就是我想要的:

images/
   folder/
       one.jpg 
       one_thumb.jpg

我怎样才能做到这一点?你可以看到,我不仅仅是简单地重命名一个现有的文件/图像。我想复制它并将其重命名到同一目录中。

只需使用复制方法:http://php.net/manual/en/function.copy.php

例如:

<?php
$file = 'images/folder/one.jpg';
$newfile = 'Images/folder/one_thumb.jpg';
if (!copy($file, $newfile)) {
    echo "failed to copy";
}

PHP有一个内置的函数,可以复制。这里有一个例子:

<?php
$file = 'one.jpg';
$newfile = 'one_thumb.jpg';
if (!copy($file, $newfile)) {
    echo "failed to copy $file...'n";
}
?>

该函数返回一个布尔值,指示复制是否成功。就这么简单!