Fixed problem when uploading images with spaces in the filename

master
pecesama 2007-07-18 06:18:14 +00:00
parent 0e7b1aa3a7
commit b1c0e4ca6e
3 changed files with 23 additions and 6 deletions

View File

@ -49,8 +49,8 @@ if ($user->isAdmin()) {
$_POST["url"] = $conf->urlGelato."/uploads/".$photoName; $_POST["url"] = $conf->urlGelato."/uploads/".$photoName;
} }
if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".$_FILES['photo']['name'] ) ) { if ( move_uploaded_file( $_FILES['photo']['tmp_name'], "../uploads/".sanitizeName($_FILES['photo']['name']) ) ) {
$_POST["url"] = $conf->urlGelato."/uploads/".$_FILES['photo']['name']; $_POST["url"] = $conf->urlGelato."/uploads/".sanitizeName($_FILES['photo']['name']);
} }
unset($_POST["photo"]); unset($_POST["photo"]);

View File

@ -83,7 +83,7 @@
} }
function getFile($remoteFileName) { function getFile($remoteFileName) {
$fileName = "../uploads/".getFileName($remoteFileName); $fileName = sanitizeName("../uploads/".$remoteFileName);
$str = _file_get_contents($remoteFileName); $str = _file_get_contents($remoteFileName);
if (!$handle = fopen($fileName, 'w')) { if (!$handle = fopen($fileName, 'w')) {
return false; return false;
@ -167,6 +167,20 @@
return $dirs; return $dirs;
} }
function sanitizeName($name) {
$name = preg_replace('/[\'"]/', '', $name);
$name = preg_replace('/[^a-zA-Z0-9]+/', '-', $name);
$name = trim($name, '-');
$name = strtolower($name);
//HACK: We need to rework the regular expression to allow the dot
$ext = substr($name, strlen($name)-3, strlen($name));
$body = substr($name, 0, strlen($name)-4);
$name = $body.".".$ext;
return $name;
}
function _file_get_contents($path) { function _file_get_contents($path) {
// Modified function from: // Modified function from:
// http://work.dokoku.net/Anieto2k/_file_get_contents.phps // http://work.dokoku.net/Anieto2k/_file_get_contents.phps

3
uploads/index.php Normal file
View File

@ -0,0 +1,3 @@
<?php
// Silence is golden.
?>