关闭

发布两上PHP类(邮件发传及文件上传)

734人阅读 评论(0) 收藏 举报
email.php
<?php
/*####################################
##  author:yagas                                                   ##
##  email:yagas@sohu.com                              ##
##  website:http://www.iebsoft.com                  ##
####################################*/

 

//SMTP电子邮件发送
class ieb_email{
 var $smtp;
 var $port;
 var $user;
 var $password;
 var $contentType;
 var $header;
 
 function ieb_email($SMTP, $USER, $PASSWORD, $PORT='25'){
  $this->user = $USER;
  $this->password = $PASSWORD;
  $this->smtp = $SMTP;
  $this->port = $PORT;
  
  $crlf = "/r/n";
  $this->contentType = "Content-type: text/plain; charset=/"gb2312/"".$crlf;
  $this->header = "MIME-Version:1.0".$crlf;
 }
 
 function sendmail($FROM, $TO, $SUBJECT, $BODY, $ISHTML=true){
  $socket = fsockopen($this->smtp, $this->port);
  if(!$socket){
   return 1;
   exit;
  }
  
  set_socket_blocking($socket,true);
        fputs($socket,"HELO try /r/n");
        $result = fgets($socket);
       
        fputs($socket,"AUTH LOGIN /r/n");
        $result = fgets($socket);
       
        fputs($socket,base64_encode($this->user)."/r/n");
        $result = fgets($socket);       
        fputs($socket,base64_encode($this->password)."/r/n");
        $result = fgets($socket);
       
        fputs($socket,"MAIL FROM: <$FROM>/r/n");
        $result = fgets($socket);
        if(substr($result, 0, 3) != "235"){
         return $result;
         exit;
        }
       
        fputs($socket,"RCPT TO: <$TO>/r/n");
       
        fputs($socket,"DATA/r/n");
       
        $crlf = "/r/n";
        $mail = $this->header;
       
        //是否为HTML邮件
        if($ISHTML){
         $mail .= "Content-type: text/html; charset=/"gb2312/"".$crlf;
        }else{
         $mail .= "Content-type: text/plain; charset=/"gb2312/"".$crlf;
        }
       
        $mail .= "From: $FROM".$crlf;
        $mail .= "To: $TO".$crlf;
        $mail .= "Subject: $SUBJECT".$crlf.$crlf;
        $mail .= $BODY.$crlf.".".$crlf;
       
        fputs($socket, $mail);
        fputs($socket, "QUIT/r/n");
       
        fclose($socket);
        $socket = NULL;
        return 0;
 }
 
}


/*
//声明对象

 

$mail = new ieb_email("SMTP地址", "用户名", "密码", "端口");

//发送邮件
$send = $mail->sendmail("发件人邮箱", "收件人邮箱", "邮件标题", "邮件内容", "是否为HTML邮件");

如果 $send 等于0,则发送成功,不为0则为发送失败
*/


?>

 




upload.php
 <?php
/*####################################
##  author:yagas                                                   ##
##  email:yagas@sohu.com                              ##
##  website:http://www.iebsoft.com                  ##
####################################*/
class ieb_upload{
 var $path = null;
 var $cpr = null;
 
 //设置上传的完整路径,如:
 //Windows    d:/uploads
 //Linux      /wwwroot/uploads
 function setServerPath($path){
  $this->path = $path;
 }
 
 //设置文件表单的名称,对应 <input type="file" name="ieb_file" />的name
 function setFileFormName($name){
  $this->cpr = $_FILES[$name];
 }
 
 //取得上传文件的类型信息,返回如:image/jpeg
 function getType(){
  return $this->cpr['type'];
 }
 
 
 //取得上传文件的大小信息
 //参数
 //b     返回单位为byte
 //k     返回单位为kb
 //m     返回单位为MB

 function getSize($type='b'){
  if($type == 'b'){
   return $this->cpr['size'];
  }elseif($type == 'm'){
      $size = ($this->cpr['size']/1024)/1024;
      return round($size, 2);
  }elseif($type == 'k'){
   $size = $this->cpr['size']/1024;
      return round($size, 2);
  }
 }
 
 
 //获取上传的图片的信息
 //参数:
 //width    返回已上传的图片的宽度
 //height   返回已上传图片的高度
 //type     返回已上传图片的类型,如 .jpg

 function getImageInfo($type){
  $image = getimagesize($this->cpr['tmp_name']);
  list($width,$height,$attr,$src) = each($image);
  switch($type){
   case 'width':
    return $width;
    break;
    
   case 'height':
    return $height;
    break;
    
   case 'type':
    return $this->imageExt($attr);
    break;
    
   default:
    return $src;
    break;
  }
 }
 
 //返回已上传文件的后缀名,如 .rar
 function getExt(){  
  $type = $this->getType();
  $start_position = strpos($type, '/');
  $type = substr($type, 0, $start_position);
  
  if($type == 'image'){
   return $this->getImageInfo('type');
  }else{
   $start_position = strpos($this->cpr['name'], '.');
   $ext = substr($this->cpr['name'], $start_position);
   return $ext;
  }
 }
 
 
 //将上传的文件移动到指定的上传目录中
 //参数
 //new_name  文件上传后的名称,如不指定参数,将自动随机命名已上传的文件名称
 //如果上传失败,将返回false,上传成功,将返回文件名

 function upload($new_name=''){  
  if($new_name == ''){
   $f_name = date('YmdHis', time()).rand(0, 9).$this->getExt();
  }else{
   $f_name = $new_name.$this->getExt();
  }
  $mv = false;
  if(is_uploaded_file($this->cpr['tmp_name'])){
   $mv = move_uploaded_file($this->cpr['tmp_name'], $this->path.'/'.$f_name);
   if($mv){
     chmod($this->path.'/'.$f_name, '0777');
     return $f_name;
   }else{
    return false;
   }
  }
 }
 
 private function imageExt($int){
  switch($int){
   case 1:
    return ".gif";
    break;
    
   case 2:
    return ".jpg";
    break;
    
   case 3:
    return ".png";
    break;
    
   case 4:
    return ".swf";
    break;
    
   case 6:
    return ".bmp";
    break;
    
   case 7:
   case 8:
    return ".gif";
    break;
    
   default:
    return ".jpg";
    break;
  }
 }
}
?>
下载地址:http://www.iebsoft.com/downloads/ieb_phpc.rar
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:104347次
    • 积分:1856
    • 等级:
    • 排名:千里之外
    • 原创:68篇
    • 转载:1篇
    • 译文:0篇
    • 评论:20条
    文章分类
    最新评论