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"]);
@ -359,7 +359,7 @@ if ($user->isAdmin()) {
$template->cargarPlantilla($input, $output, "template_regular_post"); $template->cargarPlantilla($input, $output, "template_regular_post");
$template->mostrarPlantilla(); $template->mostrarPlantilla();
break; break;
case "2": case "2":
$fileName = "../uploads/".getFileName($register["url"]); $fileName = "../uploads/".getFileName($register["url"]);
$x = @getimagesize($fileName); $x = @getimagesize($fileName);

View File

@ -82,8 +82,8 @@
} }
} }
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;
@ -165,7 +165,21 @@
} }
closedir($handle); closedir($handle);
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:

3
uploads/index.php Normal file
View File

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