Showing posts with label php How to rename automatically image file names while uploading?. Show all posts
Showing posts with label php How to rename automatically image file names while uploading?. Show all posts

How to rename automatically image file names while uploading?

Wednesday, November 4, 2015

Here's my upload function code:



function upload(&$file, $destinationDir = "", $destinationName = "", $secure = true){
$ret = false;
if (isset($file['tmp_name']) && isset($file['name'])){
if ($destinationName == ''){
$destinationName = $file['name'];
}

$destinationFile = $destinationDir . '/' . $destinationName;
if (move_uploaded_file($file['tmp_name'], $destinationFile)){
if ($secure){
chmod($destinationFile, 0644);
}

$ret = true;
}
}

return $ret;
}


This function can't rename file names automatically, if two files name are same, it will replace new image file to existing file.



How can I change this above function to rename files automatically while uploading to server?



Thank you very much