Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 865
Graham Avatar asked Jul 11 '12 22:07

Graham


People also ask

What do we mean copy?

1 : an imitation, transcript, or reproduction of an original work (such as a letter, a painting, a table, or a dress) 2 : one of a series of especially mechanical reproductions of an original impression also : an individual example of such a reproduction. 3 archaic : something to be imitated : model.

What means copy in computer?

First developed by Larry Tesler, copy and paste or copy is the act of duplicating text, data, files, or disks, producing two or more of the same file or segments of data. Copying a file to an alternate location, such as a USB jump drive, is a common procedure for backing up or sharing a file.

What kind of verb is copy?

verb (used with object), cop·ied, cop·y·ing. to make a copy of; transcribe; reproduce: to copy a set of figures from a book. to receive and understand (a radio message or its sender). to follow as a pattern or model; imitate.


1 Answers

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"; } 
like image 67
Sybio Avatar answered Sep 17 '22 13:09

Sybio