X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=upload.php;h=2509a6b0709ed054011f2ca1531505767199de98;hp=4d81804e701ffe95b153c3e903345bac839dccad;hb=912bdab05d6262ab07e7ea6664192f97239db3e1;hpb=eb268173999615e857af705883ce8c94c5c039dd 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; }