Skip to content

Instantly share code, notes, and snippets.

@PintuKumarPal
Created December 2, 2013 20:20
Show Gist options
  • Save PintuKumarPal/7758097 to your computer and use it in GitHub Desktop.
Save PintuKumarPal/7758097 to your computer and use it in GitHub Desktop.
<?php
//****** Function for generate random character *****************************/
function randomGenerator($strlength)
{
$str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$strshuf=str_shuffle($str);
$start=rand(0,strlen($str) - $strlength);
return substr(str_shuffle($strshuf),$start,$strlength);
}
$path_thumbs = "x:/projectname/uploads/"; //Upload Path
$uploadfilename = "Attachfile"; //File name submitted by form
$code = randomGenerator(5); //Generate random character
$fileParts = pathinfo($_FILES[$uploadfilename]['name']);
$file_name_only = stripslashes($fileParts['filename']);
$extension = $fileParts['extension'];
$UploadFileName = $file_name_only."_".$code.".$extension"; //Make a new file name
move_uploaded_file($_FILES[$formname]["tmp_name"],$path_thumbs.$UploadFileName); //upload file
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment