How would I copy the image from $prepicurl to $varpicurl without deleting the image $prepicurl? $prepicurl = '../images/premade/premade_test.gif'; $varpicurl = '../uploads/img/test.gif'; $newimg = 'img'.mt_rand(0,1000).mt_rand(0,999).'.gif'; $copyimage = copy($prepicurl, $newimg); $saveimage = rename("../images/premade/$newimg", $varpicurl); PHP: Thanks.
Copy the actual file itself (.gif). Basically what I need is like rename(loc1,loc2) to move the file but what I need is the file to be duplicated so I can still have it in directory 1 yet the same file is in directory 2 under the new name. Before: Directory 1 --> bob.gif Directory 2 --> (empty) After: Directory 1 --> bob.gif Directory 2 --> foo.gif (foo.gif is the same file as bob.gif it is just under a new name)
<?php $file = file_get_contents("bob.gif"); file_put_contents("foo.gif", $file); ?> PHP: or <?php copy('bob.gif', 'foo.gif'); ?> PHP: This will create a copy of bob.gif except under a different name (foo.gif), feel free to change it accordingly such as paths/directories etc.
This duplicates the file bob.gif (thats in directory1) to directory2 with the name foo.gif. The directories must already exist (although you could just use mkdir()). <?php $path = dirname(__FILE__).'/'; copy($path.'directory1/bob.gif', $path.'directory2/foo.gif') || die('Failed to copy'); ?> PHP: