网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 代码交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

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

Reply
 
Thread Tools Display Modes
  #1   IP: 59.60.149.106
Old 2008-03-06, 10:48 AM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default 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:

Code:
<?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>";
?>
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
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

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 06:28 PM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.