php
$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
if (file_exists(UPLOAD_PATH)) {
$deny_ext = array(".php",".php5",".php4",".php3",".php2",".php1",".html",".htm",".phtml",".pht",".pHp",".pHp5",".pHp4",".pHp3",".pHp2",".pHp1",".Html",".Htm",".pHtml",".jsp",".jspa",".jspx",".jsw",".jsv",".jspf",".jtml",".jSp",".jSpx",".jSpa",".jSw",".jSv",".jSpf",".jHtml",".asp",".aspx",".asa",".asax",".ascx",".ashx",".asmx",".cer",".aSp",".aSpx",".aSa",".aSax",".aScx",".aShx",".aSmx",".cEr",".sWf",".swf",".ini");
$file_name = trim($_FILES['upload_file']['name']);
$file_name = deldot($file_name);//删除文件名末尾的点
$file_ext = strrchr($file_name, '.');
$file_ext = strtolower($file_ext); //转换为小写
$file_ext = str_ireplace('::$DATA', '', $file_ext);//去除字符串::$DATA
$file_ext = trim($file_ext); //收尾去空
if (!in_array($file_ext, $deny_ext)) {
$temp_file = $_FILES['upload_file']['tmp_name'];
$img_path = UPLOAD_PATH.'/'.$file_name;
if (move_uploaded_file($temp_file, $img_path)) {
$is_upload = true;
} else {
$msg = '上传出错!';
}
} else {
$msg = '此文件不允许上传!';
}
} else {
$msg = UPLOAD_PATH . '文件夹不存在,请手工创建!';
}
}
".htaccess" 是一个用于配置 Apache 服务器的配置文件。它可以用来控制网站的访问权限、重定向 URL、设置错误页面、启用压缩等。通过修改 ".htaccess" 文件,您可以对网站的行为和功能进行一些定制。通常,这个文件放置在网站的根目录中,并且以点号开头,因此在文件系统中可能看不到它,需要打开隐藏文件才能看到。
.htaccess参数
常见配法有以下几种:
php
AddHandler php5-script .jpg
AddType application/x-httpd-php .jpg
Sethandler application/x-httpd-php
Sethandler
将该目录及子目录的所有文件均映射为php文件类型。
Addhandler
使用 php5-script 处理器来解析所匹配到的文件。
AddType
将特定扩展名文件映射为php文件类型。
我创建一个.htaccess写入
php
<FilesMatch "shell.jpg">
Sethandler application/x-httpd-php
FilesMatch用于Apache配置文件中的FilesMatch指令,用于匹配特定文件名的文件。
再将php文件改成图片格式jpg
之后先传.htaccess文件再传jpg--注意不要在本关下创建.htaccess。
这是先传的.htaccess
在传jpg
没有解析成功,照常理应该能成功