導航:首頁 > 文件處理 > php自動壓縮

php自動壓縮

發布時間:2025-09-26 15:45:43

① 如何利用php把上傳的圖片壓縮

<?php
//Thefile
$filename='test.jpg';
$percent=0.5;

//Contenttype
header('Content-Type:image/jpeg');

//Getnewdimensions
list($width,$height)=getimagesize($filename);
$new_width=$width*$percent;
$new_height=$height*$percent;

//Resample
$image_p=imagecreatetruecolor($new_width,$new_height);
$image=imagecreatefromjpeg($filename);
imageresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);

//Output
imagejpeg($image_p,null,100);
?>

http://php.net/manual/en/function.imageresampled.php

② PHP網頁上打包文件生成壓縮文件zip,並彈出下載

既然你只是想學習如何打包.


那我重點就回答你這一塊,正好我剛剛用到;

$filename="./".date('YmdH').".zip";//最終生成的文件名(含路徑)
//生成文件
$zip=newZipArchive();//使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('無法打開文件,或者文件創建失敗');
}

//$fileNameArr就是一個存儲文件路徑的數組比如array('/a/1.jpg,/a/2.jpg....');

foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二個參數是放在壓縮包中的文件名稱,如果文件可能會有重復,就需要注意一下
}
$zip->close();//關閉

//下面是輸出下載;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
header('Content-disposition:attachment;filename='.basename($filename));//文件名
header("Content-Type:application/zip");//zip格式的
header("Content-Transfer-Encoding:binary");//告訴瀏覽器,這是二進制文件
header('Content-Length:'.filesize($filename));//告訴瀏覽器,文件大小
@readfile($filename);//輸出文件;

③ php 怎麼對url的參數串進行壓縮和解壓

如果參數名和值全部是已知的,那麼做一個映射表就可以了。
如果參數的值涉及用戶提交的內容,對於過長的內容,最好使用POST,並開啟Gzip壓縮。

關於URL的長度:
1,普通用戶很少通過修改url來實現跳轉
2,太短的參數名稱就很難理解含義,比如content如果縮短成c,你知道這代表什麼意思么?
3,如果說為了便於保存和分享,那麼可以考慮short url的處理方式
4,url的長度對性能的影響微乎其微,除非是超長文本,那就是程序設計的問題了
5,如果說刻意追求極短的url,還要進行壓縮和解壓縮步驟,真的有點畫蛇添足了

④ php如何實現兩個文件先壓縮成一個壓縮包然後下載

$filename="./".date('YmdH').".zip";//最終生成的文件名(含路徑)
//生成文件
$zip=newZipArchive();//使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('無法打開文件,或者文件創建失敗');
}

//$fileNameArr就是一個存儲文件路徑的數組比如array('/a/1.jpg,/a/2.jpg....');

foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二個參數是放在壓縮包中的文件名稱,如果文件可能會有重復,就需要注意一下
}
$zip->close();//關閉

//下面是輸出下載;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
header('Content-disposition:attachment;filename='.basename($filename));//文件名
header("Content-Type:application/zip");//zip格式的
header("Content-Transfer-Encoding:binary");//告訴瀏覽器,這是二進制文件
header('Content-Length:'.filesize($filename));//告訴瀏覽器,文件大小
@readfile($filename);//輸出文件;

⑤ php 怎把上傳的rar zip文件 自動解壓 用的是哪個函數 求高手指點 告急 謝謝 求源代碼

/**
* PHP在線壓縮/解壓實例
*/

date_default_timezone_set('prc');

$zip = new engine_compress_decompress();

if (isset($_POST))
{
$sourcePath = ''; //默認位置

if (isset($_FILES['upfile'])) //上傳文件
{
$stmp = $zip->fileUpload('upfile');
$sourcePath = $stmp['sourcefile'];
$upfileError = $stmp['error'];
}
elseif (isset($_POST['inputfile'])) //輸入目錄或者文件
{
$sourcePath = $_POST['inputfile'];
}
elseif (isset($_POST['decompresssourcefiles'])) //解壓縮提交
{
$isDecompress = $zip->decompress($_POST['decompresssourcefiles'], $_POST['topath']);
if (!empty($isDecompress['filelist']))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#decompress\'</script>';
}

}

$fileList = $zip->fileArray($sourcePath); //解壓縮文件列表

if (isset($_POST['compressinputfileorfolder'])) //壓縮文件目錄或者文件輸入
{
$sourcePath = $_POST['compressinputfileorfolder'];
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
$compressFilelist = $zip->compressFileArray($sourcePath); //壓縮文件列表
}
elseif ((isset($_POST['selectcompressfilelist'])) && (isset($_POST['compresssavefilename'])))
{
$compressFiles = $zip->compress($_POST['selectcompressfilelist'], $_POST['compresssavefilename']); //真實檢測
$isCompress = $zip->CompileZipFile($compressFiles, $zip->savePath, 'all');
if (!empty($isCompress))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
}
}
}

⑥ php如何壓縮一個文件夾裡面所有的文件到zip文件裡面

//函數:文件壓縮 //壓縮參數:需要壓縮的文件或文件夾(文件可為數組),壓縮後的zip文件名及存放路徑,壓縮類型1:文件夾2:文件,後續操作1:壓縮後下載;2:存放在伺服器上(默認為/@Upload下) //壓縮文件夾示例:Tozip("./","../".date("d-H-i-s").".zip",1,2); //壓縮文件示例: // $aaa=array("../1.txt","../2.txt"); // Tozip($aaa,"../2.zip",2);FunctionTozip($Path, $ZipFile, $Typ=1, $Todo=1){//IF(!is_writeable($Path)){Exit("文件夾不可寫!");}$Path=Str_iReplace("\\","/",($Path));IF(Is_Null($Path) OrEmpty($Path) Or!IsSet($Path)){ReturnFalse;}IF(Is_Null($ZipFile) OrEmpty($ZipFile) Or!IsSet($ZipFile)){ReturnFalse;} Include_once("inc/Class_Zip.php");$zip=NewPHPZip;IF(SubStr($Path,-1,1)=="/"){$Path=SubStr($Path,0, StrLen($Path)-1);} OB_end_clean();Switch($Typ){Case"1":$zip-ZipDir($Path, $ZipFile, $Todo);Break;Case"2":$zip-ZipFile($Path,

閱讀全文

與php自動壓縮相關的資料

熱點內容
怎麼用python寫網站 瀏覽:312
捷達壓縮機啟動沒風怎麼回事 瀏覽:29
編譯原理et代表啥 瀏覽:767
androidtelnet客戶端 瀏覽:308
傅里葉pdf 瀏覽:143
季雲伺服器價格 瀏覽:564
安卓沒電池怎麼關機 瀏覽:419
安卓如何下載newstate 瀏覽:515
安卓jks是什麼 瀏覽:611
整理一個文件夾中重復照片 瀏覽:837
php自動壓縮 瀏覽:150
單片機編程自動計數 瀏覽:839
配外殼文件夾 瀏覽:472
安卓什麼app內存小於1m 瀏覽:966
幾何光學pdf 瀏覽:979
映像裡面的軟體一般在哪個文件夾 瀏覽:342
上海數據文檔加密價格 瀏覽:493
十字樑柱節點箍筋加密圖片 瀏覽:135
安卓手機怎麼更改桌面文件夾 瀏覽:250
解壓縮全能王暴力下載 瀏覽:314