<?php
//接收get方式发过来的seed信息
$imageDirectory = $_GET['seed'];
$todaydate=date('Y-m-j');
//检测目录是否存在,如果不存在,则创建目录
if(!is_dir("./file/$todaydate/$imageDirectory")) mkdir("./file/$todaydate/", 0755);
//取得客户端文件的名称并查找.在其中最后一次出现的位置
$dotLocation = strrpos($_FILES['Filedata']['name'], '.');
//substr是返回从指定位置开始的指定长度字符串
$newFileName =sanitizeText(substr($_FILES['Filedata']['name'], 0, $dotLocation)) . substr($_FILES['Filedata']['name'], $dotLocation);
//$_FILES['Filedata']['tmp_name']表示文件上传到服务器端后临时的文件名
//move_uploaded_file() 函数将上传的文件移动到新位置
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./file/$todaydate/" . $newFileName);
//PHP chmod() 函数改变文件模式,0777为
chmod("./file/$todaydate/".$_FILES['Filedata']['name'], 0777);
function sanitizeText($text)
{
// Get rid of any html tags
$title = strip_tags($text); //剥去 HTML、XML 以及 PHP 的标签
// 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;
}
?>
评论1
最新资源