A. 如何用PHP实现网页截图
代码如下:
<?php
set_time_limit(60);
//截屏
$im=imagegrabscreen();
imagepng($im,"snap1.png");
//抓取IE窗口
$browser=newCOM("InternetExplorer.Application");
$handle=$browser->HWND;
$browser->Visible=true;
$im=imagegrabwindow($handle);
$browser->Quit();
imagepng($im,"snap2.png");
$im=imagegrabscreen();
//抓取IE窗口及窗口内容(IE为例)
$browser=newCOM("InternetExplorer.Application");
$handle=$browser->HWND;
$browser->Visible=true;
$browser->Navigate("http://www..com");
while($browser->Busy){
com_message_pump(4000);
}
$im=imagegrabwindow($handle,0);
$browser->Quit();
imagepng($im,"snap3.png");
//IE全屏模式
$browser=newCOM("InternetExplorer.Application");
$handle=$browser->HWND;
$browser->Visible=true;
$browser->FullScreen=true;
$browser->Navigate("http://www..com");
while($browser->Busy){
com_message_pump(4000);
}
$im=imagegrabwindow($handle,0);
$browser->Quit();
imagepng($im,"snap4.png");
//生成网站缩略图
$browser=newCOM("InternetExplorer.Application");
$handle=$browser->HWND;
$browser->Visible=true;
$browser->Fullscreen=true;
$browser->Navigate("http://www..com");
while($browser->Busy){
com_message_pump(4000);//等待4秒
}
$im=imagegrabwindow($handle,0);//抓取网页图像,需要php5.2.2以上版本的支持
$browser->Quit();
$new_img=imagecreatetruecolor(200,150);
imageresampled($new_img,$im,0,0,0,0,200,150,1024,768);
imagejpeg($new_img,'snap5.jpg',100);
imagedestroy($new_img);
echo"Done!";
?>
B. 怎样用php实现上传图片到数据库
<?php
@session_start();
require_once("./conf/config.php");
$file_type = $_FILES["pic"]["type"];
$file_name = $_FILES["pic"]["name"];
if ((($file_type == "image/gif")
|| ($file_type == "image/jpeg")
|| ($file_type == "image/pjpeg"))
&& ($_FILES["pic"]["size"] < 1000000))
{
if(!is_dir("upload/". date("md") . "/"))
{
mkdir("upload/". date("md") . "/");
}
if (file_exists("upload/" . date("md") . "/" . $file_name))
{
echo "图片 " . $file_name . " 文件名已存在,请更换文件名再进行上传. ";
}
else
{
$url = "upload/" . date("md") . "/" .$file_name;
move_uploaded_file($_FILES["pic"]["tmp_name"],
"upload/" . date("md") . "/" . $file_name);
}
}
else
{
echo "图片文件不可用";
}
$userId = $_SESSION["userId"];
if($url){
$sql = "insert into photos(url, userId) values('$url', '$userId')";
$query = mysql_query($sql);
if($query){
die('<script>alert("图片上传成功");window.location="/photolist.htm";</script>');
}
}
?>