<?php
//create the directory if doesn't exists (should have write permissons)
$imageDirectory = $_GET['seed'];
//if(!is_dir("./files")) mkdir("./files", 0755);
if(!is_dir("./images/uploaded/$imageDirectory")) mkdir("./images/uploaded/", 0755);
//if(!is_dir("./files/thumb")) mkdir("./files/thumb", 0755);
//move the uploaded file
$dotLocation = strrpos($_FILES['Filedata']['name'], '.');
$newFileName =sanitizeText(substr($_FILES['Filedata']['name'], 0, $dotLocation)) . substr($_FILES['Filedata']['name'], $dotLocation);
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./images/uploaded/" . $newFileName);
chmod("./images/uploaded/".$_FILES['Filedata']['name'], 0777);
function sanitizeText($text)
{
// Get rid of any html tags
$title = strip_tags($text);
// Preserve escaped octets.
$title = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $title);
// Remove percent signs that are not part of an octet.
$title = str_replace('%', '', $title);
// Restore octets.
$title = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title);
$title = strtolower($title);
$title = preg_replace('|/+|', '-', $title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');
return $title;
}
?>
评论0