PHP上傳壓縮包並自解壓方法

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   檔案   for   

1、PHP上傳壓縮包並解壓的大概流程:

普通上傳功能->上傳到伺服器->載入系統組件->找到上傳的檔案並執行解壓命令->成功解壓到目錄

 

2、php執行系統命令的幾類函數:(1)system() 輸出並返回最後一行shell結果。(2)exec() 不輸出結果,返回最後一行shell結果(3)passthru() 只調用命令,把運行結果原樣地輸出(4)new com()  系統預定義com類,根據需要任意選擇內建方法(操作方式再麻煩,但也是功能最全的) 3、Com組件的用法:(1)$obj=new com("wscript.shell");//載入wscript.shell用來執行dos命令的組件(2)$obj->run(“所要執行的命令內容”);//所要執行的命令和返回參數 由於只是說明原理,一些安全驗證判斷就不寫出來了,大家可以自行補充。通俗易懂,直接上代碼:(記得開啟php.ini裡的com.allow_dcom = true)
 1 <?php 2      3     if($_POST[‘submit‘]){ 4         $tmpname=$_FILES[‘filename‘][‘tmp_name‘]; 5         $filename=$_FILES[‘filename‘][‘name‘]; 6         $path=getcwd();//擷取目前的目錄的絕對路徑 7         $filepath=$path.‘\\‘.$filename;     8  9         move_uploaded_file($tmpname, $filename);10 11         $obj=new com(‘wscript.shell‘);12         //雙引號可以解析變數13         $obj->run("winrar x $filepath $path",1,true);14         //刪除源檔案15         @unlink($filename);16 17 18     }19 20 21 ?>22 23 24     <form action="" method="post" enctype="multipart/form-data">25         上傳檔案:<input type="file" name="filename"/>26         <input type="submit" name="submit" value="上傳檔案並解壓">27     </form>

輕鬆搞定~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.