Answer the question
In order to leave comments, you need to log in
How to copy a file using php?
How to make the php script copy the file file.txt to the ../folder directory and name it with a random name and a random extension from the list (png, jpg, exe)
For example, to get copies of the file.txt file: h8y9z59h.exe, y3i2jyd3.png , 28pelsb4.jpg, 3vs3dwo3.png....
Answer the question
In order to leave comments, you need to log in
function getRNDFiles($file, $number) {
$symbols = array_merge(range('a', 'z'), range(0, 9));
$exts = array('exe', 'png', 'jpg');
for ($it = 1; $it <= $number; $it++) {
shuffle($symbols);
$number_symbols = mt_rand(8, 10);
$new_filename = '';
for ($it_symbol = 1; $it_symbol <= $number_symbols; $it_symbol++) {
$new_filename .= $symbols[array_rand($symbols)];
}
$new_filename .= '.'.$exts[array_rand($exts)];
copy($file, './folder/'.$new_filename);
}
return true;
}
getRNDFiles('./file.txt', 10);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question