From: Jason Woofenden Date: Tue, 3 Nov 2015 03:13:12 +0000 (-0500) Subject: upload.php cleanup: really don't make dot files X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=912bdab05d6262ab07e7ea6664192f97239db3e1 upload.php cleanup: really don't make dot files --- diff --git a/upload.php b/upload.php index 4d81804..2509a6b 100644 --- a/upload.php +++ b/upload.php @@ -103,11 +103,17 @@ function generate_filename($path, $mime = 'text/plain') { # replace symbols with underscores $filename = preg_replace('|[^a-z0-9_.]|', '_', $filename); + # limit length + if(strlen($filename > 80)) { + $filename = substr($filename, -80); + } + # remove dots from the beginning (no invisible files) $filename = preg_replace('|^\.*|', '', $filename); - if(strlen($filename > 80)) { - $filename = substr($filename, -80); + # make sure there's something before the extension + if ($filename == '') { + return '_'; } # fix extension @@ -127,6 +133,7 @@ function generate_filename($path, $mime = 'text/plain') { } $filename = $basename . '.' . $ext; } + return $filename; }