I have a site that you can upload an image. It works great but the uploaded image names are way too long - "swag_526abccf5e2bcd27d2000e3f9.jpg" I would like to shorten them to about 8 characters after the "swag_" part.
function SaveUploadFile($file, $dir, $resize=TRUE, $maxw=0, $maxh=0, $quality=75)
{
if(!$GLOBALS['image_verification']) $resize = FALSE;
if ($file['tmp_name'])
{
$dotpos = strrpos($file['name'], ".");
if ($dotpos) $ext = strtolower(substr($file['name'], $dotpos));
else $ext = "";
$newname = uniqid("swag_") . substr(md5($file['name']), 5, 12) . $ext;
if ($resize && ($ext==".jpg" || $ext==".jpeg" || $ext==".jfif")) $copysuccess = SaveResizedJPG($file['tmp_name'], "$dir/$newname", $maxw, $maxh, $quality);
else $copysuccess = copy($file['tmp_name'], "$dir/$newname");
if ($copysuccess)
$ret = $newname;
else
return "";
unlink($file['tmp_name']);
return $ret;
}
else
{
return "";
}
I think it has to do with the numbers 5 and 12 after newname ?
$newname = uniqid("swag_") . substr(md5($file['name']), 5, 12) . $ext;
, but I don't understand how to change this to get the results I want. Thank you for your help