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

被刻印的时光 ゝ 提交于 2019-12-03 23:13:17

Just use the copy method: http://php.net/manual/en/function.copy.php

Ex:

<?php
$file = 'images/folder/one.jpg';
$newfile = 'Images/folder/one_thumb.jpg';

if (!copy($file, $newfile)) {
    echo "failed to copy";
}

PHP has a function, copy built-in that can do this. Here's an example:

<?php
$file = 'one.jpg';
$newfile = 'one_thumb.jpg';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
?>

The function returns a boolean indicating whether the copy was successful. It's as simple as that!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!