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>');
}
}
?>