This is the scenario.

I have a defaultimage in an 'images' folder.

When someone registers it creates a directory like so:


Each time someone registers i want also the defualtimage to be copied to the new users directory, so they then have an image to start off with.



Edited by brants91: n/a

6 Years
Discussion Span
Last Post by ramsiva

To copy an image from one folder to another, you'll have to read from the image file that you would like to copy, then create another file preferably with the same name as the original file in the directory to which you would like to copy it into. here is php code to illustrate this.

//I don't know what the name of your main directory is but i'll assume for this //example it is users
//Now your default image is in an images directory.....

//The code
$img = default_image.png; //name of file to be copied
//read the file
$fp = fopen('images/'.$img3, 'r') or die("Could not contact $img3");
$page_contents = "";
while ($new_text = fread($fp, 100)) 
$page_contents .= $new_text;

chdir($new_userid."/images"); //This moves you from the current directory user to the images directory in the new user's directory

$newfile = "default_image.png"; //name of your new file
//create new file and write what you read from old file into it
$fd = fopen($newfile, 'w');
fwrite($fd, $page_contents);
fclose ($fd);//close the file

If you want it copied use the copy() command.
If you want the file moved, use rename() command.

Check the php.net manual for usage - it's very simple.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.