例1,
<?php
/**
* 下载网页代码
* edit www.
*/
$url = "http://www.";
$contents = file_get_contents($url);
$file=fopen("/www/web.doc",'w');
fwrite($file,$contents);
fclose($file);
?>
例2,
<?php
/**
* 下载远程图片
* @param string $url 图片的绝对url
* @param string $filepath 文件的完整路径(包括目录,不包括后缀名,例如/www/images/test) ,此函数会自动根据图片url和http头信息确定图片的后缀名
* @return mixed 下载成功返回一个描述图片信息的数组,下载失败则返回false
*/
function downloadImage($url, $filepath) {
//服务器返回的头信息
$responseHeaders = array();
//原始图片名
$originalfilename = '';
//图片的后缀名
$ext = '';
$ch = curl_init($url);
//设置curl_exec返回的值包含Http头
curl_setopt($ch, CURLOPT_HEADER, 1);
//设置curl_exec返回的值包含Http内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//设置抓取跳转(http 301,302)后的页面
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//设置最多的HTTP重定向的数量
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
//服务器返回的数据(包括http头信息和内容)
$html = curl_exec($ch);
//获取此次抓取的相关信息
$httpinfo = curl_getinfo($ch);
curl_close($ch);
if ($html !== false) {
//分离response的header和body,由于服务器可能使用了302跳转,所以此处需要将字符串分离为 2+跳转次数 个子串
$httpArr = explode()("\r\n\r\n", $html, 2 + $httpinfo['redirect_count']);
//倒数第二段是服务器最后一次response的http头
$header = $httpArr[count($httpArr) - 2];
//倒数第一段是服务器最后一次response的内容
$body = $httpArr[count($httpArr) - 1];
$header.="\r\n";
//获取最后一次response的header信息
preg_match_all('/([a-z0-9-_]+):\s*([^\r\n]+)\r\n/i', $header, $matches);
if (!empty($matches) && count($matches) == 3 && !empty($matches[1]) && !empty($matches[1])) {
for ($i = 0; $i < count($matches[1]); $i++) {
if (array_key_exists($i, $matches[2])) {
$responseHeaders[$matches[1][$i]] = $matches[2][$i];
}
}
}
//获取图片后缀名
if (0 < preg_match('{(?:[^\/\\\\]+)\.(jpg|jpeg|gif|png|bmp)$}i', $url, $matches)) {
$originalfilename = $matches[0];
$ext = $matches[1];
} else {
if (array_key_exists('Content-Type', $responseHeaders)) {
if (0 < preg_match('{image/(\w+)}i', $responseHeaders['Content-Type'], $extmatches)) {
$ext = $extmatches[1];
}
}
}
//保存文件
if (!empty($ext)) {
$filepath .= ".$ext";
//如果目录不存在,则先要创建目录
CFiles::createDirectory(dirname($filepath));
$local_file = fopen($filepath, 'w');
if (false !== $local_file) {
if (false !== fwrite($local_file, $body)) {
fclose($local_file);
$sizeinfo = getimagesize($filepath);
return array('filepath' => realpath($filepath), 'width' => $sizeinfo[0], 'height' => $sizeinfo[1], 'orginalfilename' => $originalfilename, 'filename' => pathinfo($filepath, PATHINFO_BASENAME));
}
}
}
}
return false;
}
?>使用PHPMailer类发邮件的例子:
<?php
/**
* phpmailer发送邮件实例
* 发送网易邮箱126.com
* edit www.
*/
require_once('../class.phpmailer.php');
$mail= new PHPMailer();
$body= "发送邮件成功";
//采用SMTP发送邮件
$mail->IsSMTP();
//邮件服务器
$mail->Host = "smtp.126.com";
$mail->SMTPDebug = 0;
//使用SMPT验证
$mail->SMTPAuth = true;
//SMTP验证的用户名称
$mail->Username = "xxx@126.com";
//SMTP验证的秘密
$mail->Password = "password";
//设置编码格式
$mail->CharSet = "utf-8";
//设置主题
$mail->Subject = "测试";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
//设置发送者
$mail->SetFrom('xxx@126.com', 'test');
//采用html格式发送邮件
$mail->MsgHTML($body);
//接受者邮件名称
$mail->AddAddress("xxx@126.com", "test");//发送邮件
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
需要引入phpmailer类文件,下载地址:PHPMailer邮件发送类V5.1下载地址。
您可能感兴趣的文章:
PHPMailer发送邮件的实例分享
phpmailer发送gmail邮件的例子
phpmailer发送yahoo邮件的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPmailer发送邮件及乱码问题的解决
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
使用phpmailer发送邮件的例子
PHPMailer类发邮件的例子:
<?php
/**
* phpmailer应用实例
* 发送yahoo邮件
* edit www.
*/
require_once('../class.phpmailer.php');
$mail= new PHPMailer();
$body= "发送邮件成功";
//采用SMTP发送邮件
$mail->IsSMTP();
//邮件服务器
$mail->Host = "smtp.mail.yahoo.com.cn";
$mail->SMTPDebug = 0;
//使用SMPT验证
$mail->SMTPAuth = true;
//SMTP验证的用户名称
$mail->Username = "********@yahoo.cn";
//SMTP验证的秘密
$mail->Password = "y*********";
//设置编码格式
$mail->CharSet = "utf-8";
//设置主题
$mail->Subject = "测试";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
//设置发送者
$mail->SetFrom('*******@yahoo.cn', 'test');
//采用html格式发送邮件
$mail->MsgHTML($body);
//接受者邮件名称
$mail->AddAddress("*********@yahoo.com", "test");//发送邮件
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
需要引入phpmailer类文件,下载地址:PHPMailer邮件发送类V5.1下载地址。
您可能感兴趣的文章:
PHPMailer发送邮件的实例分享
phpmailer发送gmail邮件的例子
phpmailer发送网易126邮箱的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPmailer发送邮件及乱码问题的解决
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
使用phpmailer发送邮件的例子