php copy and paste files on server? move files on server?
I was wondering how possible it开发者_C百科 is with PHP to copy a file from one directory on a server and paste it into another. I have a system that when a user registers creates a sub directory called the same as there username, I then want to copy a file called profile.php from a sub directory called users and paste it in the new directory with the name of the user?
You shouldn't do it this way.
There must be just one profile.php, serving all users. That's the way how PHP works. It is used to create dynamical sites, producing dynamical content based on user's input.
So, based on entered username, it should display particular user's info. One script to serve all users.
The PHP copy()
function just copies a file from one directory to another.
http://php.net/manual/en/function.copy.php
As Col. Shrapnel suggest, you shouldn't copy the profile.php for each user. That will be hard to maintain, and unnecessary duplication. But here's how you can make subdirectories for each of your users.
<?php
$username = 'me';
if(userregisters) {
mkdir('/file/to/path/{$username}');
}
精彩评论