發新話題

[分享] 上傳附件自動壓縮

上傳附件自動壓縮

程式名稱: 壓縮論壇附件
程式作者: 夜之戀
增補作者: 夜之戀
技術支援: 訪客無法瀏覽此圖片或連結,請先 註冊登入會員 夜之戀綜合社區
版權聲明: 轉載請註明夜之戀綜合社區
說  明: 未有說明

注意, 本插件供學習測試用, 如果同時大量上傳檔案有可能會做成效能問題!!

post.func.php
複製內容到剪貼板
代碼:
                if(!$attach_saved && @is_readable($attach['tmp_name'])) {
                        @$fp = fopen($attach['tmp_name'], 'rb');
                        @flock($fp, 2);
                        @$attachedfile = fread($fp, $attach['size']);
                        @fclose($fp);

                        @$fp = fopen($target, 'wb');
                        @flock($fp, 2);
                        if(@fwrite($fp, $attachedfile)) {
                                @unlink($attach['tmp_name']);
                                $attach_saved = true;
                        }
                        @fclose($fp);

                }
下加

UTF8
複製內容到剪貼板
代碼:
        if(!in_array($attach['ext'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp','rar','zip'))) {
                if($attach_saved) {
                        @$zipfile = new zipfile();
                        @$fp = fopen($target, 'rb');
                        @flock($fp, 2);
                        @$attachedfile = fread($fp, $attach['size']);
                        @$zipfile -> addFile($attachedfile, stripslashes(mb_convert_encoding($attach['name'],'big5','utf-8')));
                        @fclose($fp);
                        
                        @$dump_buffer = $zipfile -> file();
                        
                        @$fp = fopen($target . '.zip', 'wb');
                        if($fp){
                                @fwrite( $fp, $dump_buffer );
                                @fclose( $fp );
                                @$attach['size'] = filesize($target . '.zip');
                                $attach['name'] = $attach['name'] . '.zip';
                                $attach['attachment'] = $attach['attachment'] . '.zip';
                                @unlink($target);
                                $attach_saved = true;
                        }
                }
        }
如使用 UTF8 , 壓縮檔中文字無法顯示 或有錯誤 則改成
複製內容到剪貼板
代碼:
        if(!in_array($attach['ext'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp','rar','zip'))) {
                if($attach_saved) {
                        @$zipfile = new zipfile();
                        @$fp = fopen($target, 'rb');
                        @flock($fp, 2);
                        @$attachedfile = fread($fp, $attach['size']);
                        @$zipfile -> addFile($attachedfile, stripslashes(iconv('utf-8','big5',$attach['name'])));
                        @fclose($fp);
                        
                        @$dump_buffer = $zipfile -> file();
                        
                        @$fp = fopen($target . '.zip', 'wb');
                        if($fp){
                                @fwrite( $fp, $dump_buffer );
                                @fclose( $fp );
                                @$attach['size'] = filesize($target . '.zip');
                                $attach['name'] = $attach['name'] . '.zip';
                                $attach['attachment'] = $attach['attachment'] . '.zip';
                                @unlink($target);
                                $attach_saved = true;
                        }
                }
        }
BIG5
複製內容到剪貼板
代碼:
        if(!in_array($attach['ext'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp','rar','zip'))) {
                if($attach_saved) {
                        @$zipfile = new zipfile();
                        @$fp = fopen($target, 'rb');
                        @flock($fp, 2);
                        @$attachedfile = fread($fp, $attach['size']);
                        @$zipfile -> addFile($attachedfile, stripslashes($attach['name']));
                        @fclose($fp);
                        
                        @$dump_buffer = $zipfile -> file();
                        
                        @$fp = fopen($target . '.zip', 'wb');
                        if($fp){
                                @fwrite( $fp, $dump_buffer );
                                @fclose( $fp );
                                @$attach['size'] = filesize($target . '.zip');
                                $attach['name'] = $attach['name'] . '.zip';
                                $attach['attachment'] = $attach['attachment'] . '.zip';
                                @unlink($target);
                                $attach_saved = true;
                        }
                }
        }
post.php
複製內容到剪貼板
代碼:
require_once DISCUZ_ROOT.'./include/post.func.php';
下加
複製內容到剪貼板
代碼:
require_once DISCUZ_ROOT.'./include/zip.class.php';
上傳檔案到指定目錄

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。