年年我发



返回   年年我发 > 网站建设 > 代码交流
用户名
密码
 
注册账号 论坛帮助 会员列表 日历事件网赚工具 标记版面已读

代码交流 ASP,PHP,JSP等网站源代码下载与交流。

回复
 
主题工具 搜索本主题 显示模式
  #1   IP: 59.60.149.106
旧 2008-03-06, 10:48 AM
topvip topvip 当前离线
超级版主
 
注册日期: 2006-01-04
帖子: 611
精华: 11
现金: 4785 元
资产: 7233 元
声望: 10 topvip 正向着好的方向发展
默认 A PHP script to unzip files with file overwriting

Many web hosts use CPanel, as it offers a fairly intuitive way for people to manage their accounts. CPanel comes with a file manager that is functional, but somewhat clunky. Although CPanel offers a mechanism for extracting archives (.zip and .gz), this mechanism has one major downside: when extracting .zip files, currently existing files will not be overwritten. This makes upgrading software that is distributed in .zip packages very difficult.

To work around this limitation, I wrote a PHP script that allows users to extract .zip files and overwrite current files. It presents the user with a list of all the .zip files in the directory, and allows him/her to submit one for extraction. The whole process is quite intuitive. Here is what the interface looks like:

Please choose a file to unzip:


test.zip
test2.zip

Warning: Existing files will be overwritten.



The selected file is then unzipped.

To use the script, simply follow this procedure:
1) Upload this script via FTP (or paste the script into a new file) in the directory that contains the .zip file to unzip.
2) Run your web browser, and point it at the script
3) Select the file to unzip, and hit the “Unzip” button.

That’s it!

Make sure you delete the script after running it, as leaving it on the machine could result in a security issue.

unzip.php:

代码:
<?php // The unzip script // Created by Alex at http://www.learncpp.com // // This script lists all of the .zip files in a directory // and allows you to select one to unzip. Unlike CPanel's file // manager, it _will_ overwrite existing files. // // To use this script, FTP or paste this script into a file in the directory // with the .zip you want to unzip. Then point your web browser at this // script and choose which file to unzip. // See if there's a file parameter in the URL string $file = $_GET['file']; if (isset($file)) { echo "Unzipping " . $file . "<br>"; system('unzip -o ' . $file); exit; } // create a handler to read the directory contents $handler = opendir("."); echo "Please choose a file to unzip: " . "<br>"; // A blank action field posts the form to itself echo '<FORM action="" method="get">'; $found = FALSE; // Used to see if there were any valid files // keep going until all files in directory have been read while ($file = readdir($handler)) { if (preg_match ("/.zip$/i", $file)) { echo '<input type="radio" name="file" value=' . $file . '> ' . $file . '<br>'; $found = true; } } closedir($handler); if ($found == FALSE) echo "No files ending in .zip found<br>"; else echo '<br>Warning: Existing files will be overwritten.<br><br><INPUT type="submit" value="Unzip!">'; echo "</FORM>"; ?>
回复时引用此帖

wellcome to www.0058.net
回复


当前查看此主题的会员: 1 (0 位会员和 1 位游客)
 
主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

论坛启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
论坛跳转

相似的主题
主题 主题作者 版面 回复 最后发表
Hide your Affiliate Links using PHP file yahoo 代码交流 0 2008-02-04 10:32 PM
blog程序可真多 topvip Blog(博客)/Wiki(维客)/RSS/Cms 0 2007-05-23 01:57 AM
Php教程.经验技巧(上) sunshine 代码交流 0 2006-12-15 08:13 PM
Php入门速成 smiling 代码交流 0 2006-12-15 07:30 PM
php.ini中文解释 sunshine 服务器环境搭建 0 2006-02-04 11:05 PM


所有时间均为北京时间. 现在的时间是 06:45 AM, Free Patent & Patent Ideas


Powered by vBulletin 3.5.2 Chinese Exhibition Happy New Year
©2000 - 2008,Jelsoft Enterprises Ltd  Desiccant Molecular Sieve Weight Loss Bentonite Trade Manager