简体   繁体   中英

Copy image from one folder to another in PHP

I have a default image in an images/ folder.

When someone registers it creates a directory like so:

mkdir("../users/$new_userid/images",0755);

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

Does anyone have a suggestion on how to do this?

I would abstract out the user location so you have:

$new_user_folder = "../users/$new_userid/images";
mkdir($new_user_folder,0755);

That way you can re-use $new_user_folder and if you need to change it, you only change one var.

Then do something like (where $original_file is the exact filename of the one you want copied):

copy($original_file, $new_user_folder);

Note: not tested, but you get the idea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM