this question has answer here:
here's code: need give random name photos when being uploaded, don't know how, please help.
<?php if (isset($_post['submit'])) { $validextensions = array("jpeg", "jpg", "png"); $temporary = explode(".", $_files["file"]["name"]); $file_extension = end($temporary); if ((($_files["file"]["type"] == "image/png") || ($_files["file"]["type"] == "image/jpg") || ($_files["file"]["type"] == "image/jpeg") ) && ($_files["file"]["size"] < 1000000000000000000000000000000000000000000000000000000)//approx. 100kb files can uploaded. && in_array($file_extension, $validextensions)) { if ($_files["file"]["error"] > 0) { echo "return code: " . $_files["file"]["error"] . "<br/><br/>"; } else { echo "<span>vasa slika je uspesno prikacena...!!</span><br/>"; echo "<br/><b>ime od vasa slika:</b> " . $_files["file"]["name"] . "<br>"; echo "<b>tip:</b> " . $_files["file"]["type"] . "<br>"; echo "<b>velicina:</b> " . ($_files["file"]["size"] / 1024) . " kb<br>"; if (file_exists("upload/" . $_files["file"]["name"])) { echo $_files["file"]["name"] . " <b>vec postoji.</b> "; } else { move_uploaded_file($_files["file"]["tmp_name"], "upload/" . $_files["file"]["name"]); $imgfullpath = "http://".$_server['server_name'].dirname($_server["request_uri"].'?').'/'. "upload/" . $_files["file"]["name"]; echo "<b>link ka vasu sliku:</b><a href = '$imgfullpath' target='_blank'> " .$imgfullpath.'<a>'; } } } else { echo "<span>***niste odabrali sliku !!!***<span>"; } } ?>
the question is: how can give unique random name of pictures when being uploaded ? tittle says.
thanks.
first, read this: https://stackoverflow.com/a/2562877/2266583
then information in mind:
echo md5($path_parts['filename'] . time()) . $path_parts['extension']
Comments
Post a Comment