How to Rename,Move,Delete Uploaded files?

by barkkathulla 2013-08-22 20:11:18

This is for to remove temporary data files and to store it in required path.....

Example rename(random string) function:


function randomString($chars=8,$alphanumeric=true){

if($alphanumeric === true){
$letters = 'abcefghijklmnopqrstuvwxyz1234567890';
}
else{
$letters = 'abcefghijklmnopqrstuvwxyz';
}

return substr(str_shuffle($letters), 0, $chars);
}



Copy and rename functionality:


foreach ($files as $file) {

rename($source.$file, $destination.randomString(5).".jpg");

if (in_array($file, array(".",".."))) continue;
if (copy($source.$file, $destination.$file)) {
$delete[] = $source;
}
}



Delete a temporary file:


foreach ($files as $file) {
if (in_array($file, array(".",".."))) continue;
if (copy($source.$file, $destination.$file)) {
$delete[] = $source.$file;
}
}


Delete a temporary Directory:


foreach ($delete as $file) {
unlink($file);
}
rmdir($dira);
928
like
0
dislike
0
mail
flag

You must LOGIN to add comments