Create  directory  with  php:  script  copy  common  file  into  directory  then!  zip  up  the  directory

Posted on 2005-05-09
Last Modified: 2012-06-21
Hey experts out there! Heres an easy 500 points..

I need to create a directory based on:
$path = "C:\Program Files\Apache Group\Apache\htdocs\sites";
\\ or $path = "\var\www\http\htdocs";

$dir = "\new_dir";

the copy over filess to the new directory from a common directory:

then tar and gzip new directory:


Question by:jbrashear72
    LVL 6

    Accepted Solution

    Creating a directory is easy:

    //create the directory
    $dir = "/new_dir";
    $mode = 0700;
    mkdir($dir, $mode);

    Go here for a function that copies either a file or directory:

    Go here for a function to compress files (shown in comments)

    I'll change the code to do an entire directory....

    LVL 3

    Author Comment

    Looks good. Yea I need to zip the entire directory not just a file.
    that would help.
     So far so good.
    LVL 1

    Expert Comment

    I think you should firstly create a TAR file of your directory content and than compress (zip) it (tar.gz)
    Maybe this can help you:
    LVL 7

    Expert Comment

    You seem to be crossing OSes here. Is the source machine a Windows box and the target machine a *nix box? If so, should you use FTP to transfer the ZIP once it's done?

    shell("tar -cfz mytargz");

    Something like that. Should tar and then gzip the directory and everything in it, including respawning children nodes.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now