复制&将文件重命名为相同的目录而不删除原始文件 [英] Copy & rename a file to the same directory without deleting the original file

查看:148
本文介绍了复制&将文件重命名为相同的目录而不删除原始文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


这应该是漂亮的简单。我不想复制&重命名服务器上已经存在的图像,同时保留原始图像



以下是原始图像位置:

  images / 
文件夹/
one.jpg

这是我想要的:

  images / 
folder /
one.jpg
one_thumb.jpg

我该如何做到这一点?你可以看到我不只是重命名现有的文件/图像。我想复制它,并将其重命名为相同的目录。 只需使用复制方法: http://php.net/manual/en/function.copy.php



例:

 <?php 
$ file ='images / folder / one.jpg' ;
$ newfile ='图片/文件夹/ one_thumb.jpg';

if(!copy($ file,$ newfile)){
echofailed to copy;
}


Possible Duplicate:
Clone + Rename file with PHP

This should be pretty easy. I wan't to copy & rename images that already exist on the server while still retaining the original image.

Here's the original image location:

images/
   folder/
       one.jpg

This is what I want:

images/
   folder/
       one.jpg 
       one_thumb.jpg

How can I achieve this? You can see I'm not just simply renaming an existing file / image. I want to copy it and rename it to the same directory.

解决方案

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";
}

这篇关于复制&amp;将文件重命名为相同的目录而不删除原始文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆