X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=upload.php;h=2509a6b0709ed054011f2ca1531505767199de98;hb=912bdab05d6262ab07e7ea6664192f97239db3e1;hp=b1b33230e92a780de0d56b41e6d833f572b8d5cf;hpb=6f0496dc8fa0c71b6606456cf4bc4b65e8140ec6;p=wfpl.git diff --git a/upload.php b/upload.php index b1b3323..2509a6b 100644 --- a/upload.php +++ b/upload.php @@ -1,19 +1,9 @@ . +# This program is in the public domain within the United States. Additionally, +# we waive copyright and related rights in the work worldwide through the CC0 +# 1.0 Universal public domain dedication, which can be found at +# http://creativecommons.org/publicdomain/zero/1.0/ # This file contains functions to accept files being uplodad with the 80)) { $filename = substr($filename, -80); } + # remove dots from the beginning (no invisible files) + $filename = preg_replace('|^\.*|', '', $filename); + + # make sure there's something before the extension + if ($filename == '') { + return '_'; + } + # fix extension $last_dot = strrpos($filename, '.'); if($last_dot === false) { @@ -137,6 +133,7 @@ function generate_filename($path, $mime = 'text/plain') { } $filename = $basename . '.' . $ext; } + return $filename; } @@ -181,8 +178,8 @@ function save_uploaded_file($key, $path) { # standard places (like /usr/bin or /usr/local bin) and PHP's PATH environment # variable is not set appropriately. function path_to($prog, $or_die = true) { - $prog = ereg_replace('[^a-zA-Z0-9_.-]', '', $prog); - $prog = ereg_replace('^[-.]*', '', $prog); + $prog = preg_replace('|[^a-z0-9_.-]|i', '', $prog); + $prog = preg_replace('|^[-.]*|', '', $prog); if($prog == '') { die('Invalid argument to path_to()'); } @@ -224,7 +221,7 @@ function gif_to_png($filename, $new_filename = 'just change extension') { $new_filename .= '.png'; } - imagemagick_convert($filename, $new_filename, "$convert -colorspace RGB", 'GIF to PNG conversion'); + imagemagick_convert($filename, $new_filename, "-colorspace sRGB", 'GIF to PNG conversion'); unlink($filename); return $new_filename; @@ -258,7 +255,7 @@ function make_thumbnail($filename, $max_width = '70', $max_height = '70') { function exec_or_die($command, $doing_what) { exec($command, $dummy, $ret); if($ret != 0) { - $base = basename(ereg_replace(' .*', '', $command)); + $base = basename(preg_replace('| .*|', '', $command)); die("$doing_what failed. $base called exit($ret)"); } } @@ -280,7 +277,7 @@ function imagemagick_mogrify($in_filename, $args, $doing_what = "Image conversio } function format_int_70($str) { - $str = ereg_replace('[^0-9]', '', $str); + $str = preg_replace('|[^0-9]|', '', $str); if($str == '') { $str = '70'; } @@ -331,7 +328,7 @@ function image_w_h_or_die($filename) { # Like save_uploaded_file() (above) except that it converts all images to PNG -# or JPEG, converts to RGB colorspace, and optionally scales and/or creates a +# or JPEG, converts to sRGB colorspace, and optionally scales and/or creates a # thumbnail. And, if $path ends with a period, the correct extension will be # appended. # @@ -352,7 +349,7 @@ function image_w_h_or_die($filename) { # and names, call convert_uploaded_image(). function save_uploaded_image($key, $path, $image_width = 0, $image_height = 0, $thumbnail_width = 0, $thumbnail_height = 0) { $image_w_h_thumb_w_h = convert_uploaded_image($key, $path, $image_width, $image_height, $thumbnail_width, $thumbnail_height); - return ereg_replace(' .*', '', $image_w_h_thumb_w_h); + return preg_replace('| .*|', '', $image_w_h_thumb_w_h); } function ext_to_web_image_ext($in) { @@ -392,7 +389,7 @@ function convert_uploaded_image($key, $path, $image_width = 0, $image_height = 0 $filename = $path; } - $convert_params = '-colorspace RGB -auto-orient'; + $convert_params = '-colorspace sRGB -auto-orient'; if($image_width > 0 && $image_height > 0) { $convert_params .= " -geometry ${image_width}x$image_height"; }