1.phpä¸ä¼ å¾ç并å缩-thinkphpå¦ä½åå¾çå缩å¢ï¼
2.php 怎么压缩后 在发给前端
3.php 如何将多张压缩下载到本地 ,片压详细一点,缩上有案例更好!传源网站源码如何转换!片压谢谢各位了
phpä¸ä¼ å¾ç并å缩-thinkphpå¦ä½åå¾çå缩å¢ï¼
phpå缩å¾ç
æ¯å¦(ä»ä¹?缩上微信 摇奖 源码)ä¸é¢æä¸å大å°çå¾ç--------è¯æ表达缺主è¯,å«ç³å¯¼è´æ æ³ç解ã
æå¡å¨ä¸é¢?客æ·æºä¸é¢?å ·ä½ä»ä¹è½¯ä»¶ç¯å¢ä¸é¢?
âæä¸å大å°çå¾çâ,å·²ç»åå¨çå¾çé常已ç»å缩è¿ç,åJPEGæ´æ¯ææå缩ãå次åç¼©å¿ å®å次ä¼éä½ç»è´¨ãPHPå¯ä»¥å次å¤çå¾ç,ä½ç»è´¨ååå¨å¤§å°ä¸è½å ¼å¾,ç»è´¨å¥½å°±åå¨å¤§,è¦åå¨å°å°±ç»è´¨å·®,æ ¹æ®èªå·±çç»è´¨éæ±å¤çã
thinkphpå¦ä½åå¾çå缩å¢ï¼å¨ä¸ä¼ å¾ççæ¶åå ççå¾çæå¤å¤§,ä¸è¬æ¥è¯´å¯¼èªå¹»ç¯ççå¾çåå¼ å¤§å°å°½éä¸è¶ k,产åå¾ä¸è¶ è¿k,è¿æ ·å è½½è¿æ ¢çè¯å°±ç¨ajaxåå è½½æ¹æ³,å¯ä»¥æ¯æ»å¨å è½½ä¹ç±»,ä½æ¯å¯¹èèæå页é¢å¹¶ä¸æ¯å¾å好ã
è³äºä½ 说çç¨tpæå¾çå缩,é£åªè½æ¯å°å¾çç尺寸æ¹æä½ æ³è¦ç尺寸,大å°çè¯æ¯webæç¨æ ¼å¼å¤§å°,ç页é¢å è½½å®ä½ åæ¢åå¾,è¿æ ·ç¸å½äºåå è½½äºä¸é,è¿ä¸å¦åajaxæ»å¨å è½½ã
PHPç½ç«ä¸ä¼ å¾çèªå¨å缩ï¼æä¹ç¼ç¨åï¼æ±æè¿éä¼ä½¿ç¨å°ä¸ä¸ªæ件:
:è¿æ¥æ°æ®åº
test_:æ§è¡SQLè¯å¥
upload_:ä¸ä¼ å¾ç并å缩
ä¸ä¸ªæ件代ç å¦ä¸:
è¿æ¥æ°æ®åº:
<?php
$db_host='';
$db_user='';
$db_psw='';
$db_name='';
$db_port='';
$sqlconn=new_ysqli($db_host,$db_user,$db_psw,$db_name);
$q="set_ames_tf8;";
$result=$sqlconn->query($q);
if(mysqli_connect_errno())_
_rintf("Connect_ailed:%s\n",_ysqli_connect_error());
_xit();
}
>å½ç¶ä½¿ç¨ä¸äºå°è£ çæ°æ®åºç±»ä¹æ¯å¯ä»¥çã
æ§è¡SQLè¯å¥:test_
<?php
require("");
require("upload_");
$real_img=$uploadfile;
$small_img=$uploadfile_resize;
$insert_sql="insert_nto_mg(real_img,small_img)_alues(?,?)";
$result=$sqlconn->_repare($insert_sql);
$result->_ind_param("ss",$real_img,$small_img);
$result->_xecute();
>ä¸ä¼ å¾ç并å缩:upload_
<?php
//设置æ件ä¿åç®å½
$uploaddir="upfiles/";
//设置å 许ä¸ä¼ æ件çç±»å
$type=array("jpg","gif","bmp","jpeg","png");
//è·åæ件åç¼åå½æ°
function_ileext($filename)
{
_eturn_ubstr(strrchr($filename,'.'),1);
}
//çæéæºæ件åå½æ°
function_andom($length)
{
$hash='CR-';
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$max=_trlen($chars)-1;
_t_srand((double)microtime()*);
_or($i=0;$i<$length;$i++)
_
_$hash.=$chars[mt_rand(0,$max)];
_
_eturn$hash;
}
$a=strtolower(fileext($_FILES['filename']['name']));
//å¤ææ件类å
if(!in_array(strtolower(fileext($_FILES['filename']['name'])),$type))
{
$text=implode(",",$type);
$ret_code=3;//æ件类åé误
$page_result=$text;
$retArray=_rray('ret_code'=>$ret_code,'page_result'=>$page_result);
$retJson=_son_encode($retArray);
_cho$retJson;
_eturn;
}
//çæç®æ æ件çæ件å
else
{
$filename=explode(".",$_FILES['filename']['name']);
_o
_
_$filename[0]=random();//设置éæºæ°é¿åº¦
_$name=implode(".",$filename);
_//$name1=$name.".Mcncc";
_$uploadfile=$uploaddir.$name;
_
_hile(file_exists($uploadfile));
_f(move_uploaded_file($_FILES['filename']['tmp_name'],$uploadfile))
_
_if(is_uploaded_file($_FILES['filename']['tmp_name']))
_{
_$ret_code=1;//ä¸ä¼ 失败
_}
_lse
_//ä¸ä¼ æå
_$ret_code=0;
_
_
$retArray=_rray('ret_code'=>$ret_code);
$retJson=_son_encode($retArray);
echo$retJson;
}
//å缩å¾ç
$uploaddir_resize="upfiles_resize/";
$uploadfile_resize=$uploaddir_resize.$name;
//$pic_width_max=;
//$pic_height_max=;
//以ä¸ä¸ä¸é¢æ®µæ³¨éå¯ä»¥èå使ç¨,å¯ä»¥ä½¿å¾çæ ¹æ®è®¡ç®åºæ¥çæ¯ä¾å缩
$file_type=$_FILES["filename"]['type'];
function_esizeImage($uploadfile,$maxwidth,$maxheight,$name)
{
//åå¾å½åå¾ç大å°
$width=_magesx($uploadfile);
$height=_magesy($uploadfile);
$i=0.5;
//çæ缩ç¥å¾ç大å°
_f(($width>$maxwidth)_|($height>$maxheight))
_
_/
*_$widthratio=$maxwidth/$width;
_$heightratio=$maxheight/$height;
_
_if($widthratio<$heightratio)
_{
_$ratio=$widthratio;
_}
_else
_{
__$ratio=$heightratio;
_}
_
_$newwidth=$width*$ratio;
_$newheight=$height*$ratio;
_*/
_$newwidth=$width*$i;
_$newheight=$height*$i;
_if(function_exists("imagecopyresampled"))
_{
_$uploaddir_resize=_magecreatetruecolor($newwidth,$newheight);
__magecopyresampled($uploaddir_resize,$uploadfile,0,0,0,0,$newwidth,$newheight,$width,$height);
_}
_else
_{
_$uploaddir_resize=_magecreate($newwidth,$newheight);
__magecopyresized($uploaddir_resize,$uploadfile,0,0,0,0,$newwidth,$newheight,$width,$height);
_}
_
_ImageJpeg($uploaddir_resize,$name);
_ImageDestroy($uploaddir_resize);
_
_lse
_
_ImageJpeg($uploadfile,$name);
_
}
if($_FILES["filename"]['size'])
{
_f($file_type=="image/pjpeg"||$file_type=="image/jpg"|$file_type=="image/jpeg")
_
_//$im=_magecreatefromjpeg($_FILES[$upload_input_name]['tmp_name']);
_$im=_magecreatefromjpeg($uploadfile);
_
_lseif($file_type=="image/x-png")
_
_//$im=_magecreatefrompng($_FILES[$upload_input_name]['tmp_name']);
_$im=_magecreatefromjpeg($uploadfile);
_
_lseif($file_type=="image/gif")
_
_//$im=_magecreatefromgif($_FILES[$upload_input_name]['tmp_name']);
_$im=_magecreatefromjpeg($uploadfile);
_
_lse//é»è®¤jpg
_
_$im=_magecreatefromjpeg($uploadfile);
_
_f($im)
_
_ResizeImage($im,$pic_width_max,$pic_height_max,$uploadfile_resize);
_
_ImageDestroy($im);
_
}
>请æç §ç°å®æ åµæ´æ¹,test_ä¸å¯¹åºçä¿¡æ¯ã
æé纳,谢谢ã
php 怎么压缩后 在发给前端
<?php
/
*----------------------------------------------------------------------
函数:调整尺寸或生成缩略图
返回:True/False
参数:
$Image 需要调整的(含路径)
$Dw= 调整时最大宽度;缩略图时的绝对宽度
$Dh= 调整时最大高度;缩略图时的绝对高度
$Type=1 1,调整尺寸; 2,生成缩略图
$path='img/';//路径
$phtypes=array(
'img/gif',
'img/jpg',
'img/jpeg',
'img/bmp',
'img/pjpeg',
'img/x-png'
);
Function Img($Image,$Dw=,$Dh=,$Type=1){
IF(!File_Exists($Image)){
Return False;
}
//如果需要生成缩略图,则将原图拷贝一下重新给$Image赋值
IF($Type!=1){
Copy($Image,Str_Replace(".","_x.",$Image));
$Image=Str_Replace(".","_x.",$Image);
}
//取得文件的类型,根据不同的类型建立不同的对象
$ImgInfo=GetImageSize($Image);
Switch($ImgInfo[2]){
Case 1:
$Img = @ImageCreateFromGIF($Image);
Break;
Case 2:
$Img = @ImageCreateFromJPEG($Image);
Break;
Case 3:
$Img = @ImageCreateFromPNG($Image);
Break;
}
//如果对象没有创建成功,则说明非文件
IF(Empty($Img)){
//如果是生成缩略图的时候出错,则需要删掉已经复制的文件
IF($Type!=1){ Unlink($Image);}
Return False;
}
//如果是执行调整尺寸操作则
IF($Type==1){
$w=ImagesX($Img);
$h=ImagesY($Img);
$width = $w;
$height = $h;
IF($width>$Dw){
$Par=$Dw/$width;
$width=$Dw;
$height=$height*$Par;
IF($height>$Dh){
$Par=$Dh/$height;
$height=$Dh;
$width=$width*$Par;
}
}ElseIF($height>$Dh){
$Par=$Dh/$height;
$height=$Dh;
$width=$width*$Par;
IF($width>$Dw){
$Par=$Dw/$width;
$width=$Dw;
$height=$height*$Par;
}
}Else{
$width=$width;
$height=$height;
}
$nImg = ImageCreateTrueColor($width,$height); //新建一个真彩色画布
ImageCopyReSampled($nImg,$Img,0,0,0,0,$width,$height,$w,$h);//重采样拷贝部分图像并调整大小
ImageJpeg ($nImg,$Image); //以JPEG格式将图像输出到浏览器或文件
Return True;
//如果是执行生成缩略图操作则
}Else{
$w=ImagesX($Img);
$h=ImagesY($Img);
$width = $w;
$height = $h;
$nImg = ImageCreateTrueColor($Dw,$Dh);
IF($h/$w>$Dh/$Dw){ //高比较大
$width=$Dw;
$height=$h*$Dw/$w;
$IntNH=$height-$Dh;
ImageCopyReSampled($nImg, $Img, 0, -$IntNH/1.8, 0, 0, $Dw, $height, $w, $h);
}Else{ //宽比较大
$height=$Dh;
$width=$w*$Dh/$h;
$IntNW=$width-$Dw;
ImageCopyReSampled($nImg, $Img, -$IntNW/1.8, 0, 0, 0, $width, $Dh, $w, $h);
}
ImageJpeg ($nImg,$Image);
Return True;
}
}
><html><body>
<form method="post" enctype="multipart/form-data" name="form1">
<table>
<tr><td>上传</td></tr>
<tr><td><input type="file" name="photo" size="" /></td></tr>
<tr><td><input type="submit" value="上传"/></td></tr>
</table>
允许上传的文件类型为:<?=implode(', ',$phtypes)?></form>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
if (!is_uploaded_file($_FILES["photo"][tmp_name])){
echo "不存在";
exit();
}
if(!is_dir('img')){ //路径若不存在则创建
mkdir('img');
}
$upfile=$_FILES["photo"];
$pinfo=pathinfo($upfile["name"]);
$name=$pinfo['basename'];//文件名
$tmp_name=$upfile["tmp_name"];
$file_type=$pinfo['extension'];//获得文件类型
$showphpath=$path.$name;
if(in_array($upfile["type"],$phtypes)){
echo "文件类型不符!";
exit();
}
if(move_uploaded_file($tmp_name,传源深圳源码智能照明$path.$name)){
echo "成功!";
Img($showphpath,片压,,2);
}
echo "<img src=\"".$showphpath."\" />";
}
></body>
</html>
php 如何将多张压缩下载到本地 ,详细一点,缩上有案例更好!传源!片压谢谢各位了
php的缩上压缩方式
<?php
$zip = zip_open("/tmp/test2.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
echo "Name: " . zip_entry_name($zip_entry) . "\n";
echo "Actual Filesize: " . zip_entry_filesize($zip_entry) . "\n";
echo "Compressed Size: " . zip_entry_compressedsize($zip_entry) . "\n";
echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "\n";
if (zip_entry_open($zip, $zip_entry, "r")) {
echo "File Contents:\n";
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
echo "$buf\n";
zip_entry_close($zip_entry);
}
echo "\n";
}
zip_close($zip);
}
>用php下载多张
<?php
set_time_limit(0);//设置PHP超时时间
$aImgList = array_unique($aImgList );
foreach($aImgList as $lists) {
file_put_contents(basename($lists), file_get_contents($lists));
}
?>