目录名称合法性检测
<?php教程
//目录名称合法性检测
function isen($str){
$ret="";
for($i=0;$i $p=ord(substr($str,$i,1));
if(($p<48 & $p!=45 & $p!=46) || ($p>57 & $p<65) || ($p>90 & $p<97 & $p!=95) || $p>122){
nerror("不符合规范!");
}
$ret.=chr($p);
}
return $ret;
}
?>
这函数 过滤不安全字符
function s_addslashes($string, $force = 0) {
if(!get_magic_quotes_gpc()) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = s_addslashes($val, $force);
}
} else {
$string=str_replace("&#x","& # x",$string); //
过滤一些不安全字符
$string = addslashes($string);
}
}
return $string;
}
实例:
$_COOKIE = c_addslashes($_COOKIE);
$_POST = c_addslashes($_POST);
$_GET = c_addslashes($_GET);
在公共文件中加入
if($_FILES){
foreach( $_FILES as $key => $_value )
{
$_FILES[$key]['type'] =$_value['type'];
}
if(substr($_FILES[$key]['type'],0,6) !='image/')
{
exit;
}
}
禁止上传除图片文件以外的文件,
提示:
不要获取文件扩展名来判断类型,这样是最不安全的,我们用$_FIlES['form']
['type']
这个可以读取文件内容来识别文件类型,但它能识别的有限,不过如果你用图片就足
够了解。
www.111cn.net 本站原创,转载注明
<?php
function image2ascii( $image )
{
// return value
$ret = '';
// open the image
$img = ImageCreateFromJpeg($image);
// get width and height
$width = imagesx($img);
$height = imagesy($img);
// loop for height
for($h=0;$h<$height;$h++)
{
// loop for height
for($w=0;$w<=$width;$w++)
{
// add color
$rgb = ImageColorAt($img, $w, $h);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
// create a hex value from the rgb
$hex = '#'.str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
// now add to the return string and we are done
if($w == $width)
{
$ret .= '<br>';
}
else
{
$ret .= '<span style="color:'.$hex.';">#</span>';
}
}
}
return $ret;
}
?>
Example Usage
<?php
// an image to convert
$image = 'test.jpg';
// do the conversion
$ascii = image2ascii( $image );
// and show the world
echo $ascii;
?>
添加附件
添加一个附件
添加一或多个附件很简单,添加附件,是通过调用addAttachment方法,这种方法可以多次调用添加多个attachemnts。
布尔addAttachment($文件的字符串,字符串[$ c_type ='应用程序/八位字节流'],串[$名称=],布尔[$ isfile =真],字符串[$编码='一个base64'])
变量:
$文件:要么变量包含一个文件的内容,或文件本身的路径
$ c_type:内容类型,这意味着,例如文件的MIME类型。 text / plain的,文字/ CSV格式,应用/ PDF格式
$名称:该文件的名称,您希望它出现在电子邮件,这应该是唯一的
$ isFile:是否变量$文件是对文件或文件的内容的路径
$编码:这通常应为默认离开,除非你知道你在做什么
附件可以是在一个变量,或在服务器上的文件中存储的文件系统。在这第一个例子中,我将建立一个小型文本文件名为'你好text.txt'改为'你好世界!也。
?> 添加多个附件 <?
正如上一节,添加多个附件是rasy与调用addAttachment了。在这个例子中,我会发送一个带有两个文本附件的电子邮件。
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "Leigh <leigh@no_spam.net>"; // Who your name and email address
$recipient = "Leigh <leigh@no_spam.net>"; // The Recipients name and email address
$subject = "Test Email"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$html = '<html><body><p>This is a html message</p></body></html>'; // HTML version of the email
$crlf = "n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Add an attachment
$file = "Hello World!"; // Content of the file
$file_name = "Hello text.txt"; // Name of the Attachment
$content_type = "text/plain"; // Content type of the file
$mime->addAttachment ($file, $content_type, $file_name, 0); // Add the attachment to the email
// Add a second attachment
$file = "Hello World! Again :)"; // Content of the file
$file_name = "Hello text 2.txt"; // Name of the Attachment
$content_type = "text/plain"; // Content type of the file
$mime->addAttachment ($file, $content_type, $file_name, 0); // Add the attachment to the email
$body = $mime->get();
$headers = $mime->headers($headers);
// Sending the email
$mail =& Mail::factory('mail');
$mail->send($recipient, $headers, $body);
?>
ajax +php 二级联动菜单代码
<script language="javascript" >
var http_request=false;
function send_request(url){//初始化,指定处理函数,发送请求的函数
http_request=false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest){//Mozilla浏览器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//设置MIME类别
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE浏览器
try{
http_request=new ActiveXObject("Msxml2.XMLHttp");
}catch(e){
try{
http_request=new ActiveXobject("Microsoft.XMLHttp");
}catch(e){}
}
}
if(!http_request){//异常,创建对象实例失败
window.alert("创建XMLHttp对象失败!");
return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式,URL,及是否同步执行下段代码
http_request.open("GET",url,true);
http_request.send(null);
}
//处理返回信息的函数
function processrequest(){
if(http_request.readyState==4){//判断对象状态
if(http_request.status==200){//信息已成功返回,开始处理信息
document.getElementById(reobj).innerHTML=http_request.responseText;
}
else{//页面不正常
alert("您所请求的页面不正常!");
}
}
}
function getclass(obj){
var pid=document.form1.select1.value;
document.getElementById(obj).innerHTML="<option>loading...</option>";
send_request('doclass.php?pid='+pid);
reobj=obj;
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ajax +php 二级联动菜单代码</title>
</head>
<body>
<form name="form1">
<select name="select1" id="class1" style="width:100;" onChange="getclass('class2');">
<option selected="selected"></option>
<option value="1">大类1</option>
<option value="2">大类2</option>
</select>
<select name="select2"id="class2" style="width:100;">
</select>
</form>
</body>
</html>
php 处理代码
<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
$pid=$_GET['pid'];
$db=mysql_connect("localhost","root","7529639"); //创建数据库连接
mysql_query("set names 'GBK'");
mysql_select_db("menuclass");
$sql="select classname from menu where parentid=".$pid."";
$result=mysql_query($sql);
//循环列出选项
while($rows=mysql_fetch_array($result)){
echo '<option>';
echo $rows['classname'];
echo "</option>n";
}
?>
相关文章
- 今天小编就为大家分享一篇解决Pycharm的项目目录突然消失的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-04-22
- 这篇文章主要介绍了C#路径,文件,目录及IO常见操作,较为详细的分析并汇总了C#关于路径,文件,目录及IO常见操作,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
docker 启动elasticsearch镜像,挂载目录后报错的解决
这篇文章主要介绍了docker 启动 elasticsearch镜像,挂载目录后报错的解决,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-20- 这篇文章主要介绍了idea out目录与target目录的区别详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-08
- 今天小编大家分享一篇C#获得程序的根目录以及判断文件是否存在的实例讲解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-06-25
- 这篇文章介绍的是一个小技巧来获取node.js项目根目录,这个技巧非常实用。有需要的朋友们可以参考借鉴,下面来一起看看吧。...2016-10-02
- 我的第一个感觉就是用递归创建,具体思路如下: function Directory($dir){ if(is_dir($dir) || @mkdir($dir,0777)){ //查看目录是否已经存在或尝试创建,加一个@抑制符号是因为第一次创建失败,会报一个“父目录不存...2015-11-08
- 这篇文章主要介绍了解决docker挂载的目录无法读写问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-19
- 这篇文章主要介绍了python import 上级目录的导入,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-03
- 这篇文章主要介绍了C++递归删除一个目录的实现方法,涉及到目录的操作及递归算法的应用,需要的朋友可以参考下...2020-04-25
- 对于游戏中出现的每一样东西,比如砖块箱子水管地面,还有人物都可以看成是一个独立的物体,所以每个物体类都继承了pygame的精灵类pg.sprite.Sprite,这篇文章主要给大家介绍了关于Python Pygame中精灵和碰撞检测的相关资料,需要的朋友可以参考下...2021-10-05
- 本文主要列举出C#文件和目录操作的一些方法,包括创建、移动、遍历目录,读写文件等方法,有需要的小伙伴可以学习一下。...2020-06-25
- 这篇文章主要给大家介绍了关于如何检测JavaScript中死循环的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-08-31
- 这篇文章主要介绍了bat删除邪恶文件之畸形文件与畸形目录的方法,这些都是黑客留得后门等文件或目录,需要删除,一般直接删除就不行的,需要下面的命令或软件,下面脚本之家小编就为大家分享一下方法,需要的朋友可以参考下...2020-08-28
- 本篇文章是对C#中如何删除文件目录或文件的解决方法进行了详细的分析介绍,需要的朋友参考下...2020-06-25
- php文件夹操作函数string basename ( string path [, string suffix] )给出一个包含有指向一个文件的全路径的字符串,本函数返回基本的文件名。...2013-09-11
- 这篇文章主要介绍了python基于opencv检测程序运行效率,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-05-09
- 这篇文章主要介绍了iOS WKWebview 白屏检测实现的示例,帮助大家更好的进行ios开发,感兴趣的朋友可以了解下...2020-10-20
- 这篇文章主要介绍了Bootstrap框架动态生成Web页面文章内目录的方法,利用Bootstrap中的Affix和ScrollSpy插件便可以实现,需要的朋友可以参考下...2016-05-14
- 这篇文章介绍了C#获取全部目录和文件的简单实例,有需要的朋友可以参考一下...2020-06-25