add_file ( $source_path, $des_path )

Attached file into compression file by using absolute or relative file path.

Usage

require_once 'compress.php'; //attactched source script library compression file into your project.
$zip = new ESCompress(); // initialized ESCompress compression object.
$result = $zip->add_file('sample1.txt');  // There is a file attached into compression file.
if(!$result){
    echo 'file not exist.';
}
$zip->compress('test.zip'); // Compress by using given path.

Parameters

$source_path

(string) (required) absolute or related file path.

$des_path

(string) (optional) file path which is inside on zip file.

Return Values

(boolean) Returns true , If has been attached success or fail return (boolean) false .

Example

.1 Attached a file into compression file by using relative path. Do not change file name or path inside of compression file.

$result = $zip->add_file('sample1.txt');  // Use relative path to attached a file into compression file.
if(!$result){
    echo 'file not exist.';
}

.2 Attached a file into compression file by using absolute path.

require_once 'C:\wamp\www\sample\compress.php';
...
$result = $zip->add_file('C:\wamp\www\sample\folder\sample2.txt');  // There is a file attached into compression file.
if(!$result){
    echo 'file not exist.';
}
$result = $zip->add_file('E:\folder\sample3.txt');  // There is a file attached into compression file.
if(!$result){
    echo 'file not exist.';
}

Compression functions executed from 'C:\wamp\www\sample' folder. If attached file ( eq: 'C:\wamp\www\sample\folder\sample2.txt' ) related to 'sample' folder, Those file path are made form 'sample' folder ( eq: 'folder\sample2.txt' ) . But attached file ( eq: 'E:\folder\sample3.txt' ) not related into 'sample' folder, Get only file name ( eq: 'sample3.txt' ) form those files into compression. We do not recommenced to compression this method.

.3 Use secondary parameter to give new path and file name inside of compression file.

$result = $zip->add_file('folder\sample3.txt' ,'rename_file1.txt');  // Give as new file name.
if(!$result){
    echo 'file not exist.';
} 

$result = $zip->add_file('E:\folder\sample4.txt','sample/rename_file2.txt');  // Give as new file path.
if(!$result){
    echo 'file not exist.';
}
905

published
function () add_folder published
function () overwrite published
function () as_new published
function () compress published
function () extract published

What is the codrate ?

codrate.com is a standard, fast cross browsing and highly versatile site. It is useful for many large number of Program Development Industries. So you can get support form Codrators , who are the codrate's joiners around world to help your program developments, You can answer other codrator's questions. Communicate with them. Share your knowledge with them. Do you have an interest in programming, So publish your articles about programming. It will help to maintain your professional co-profile. Actually codrate.com is not such as a regular web site. It will be gave new experience, best narrow cross-browser view, reduce processing time to receive browsing request, it's mean do not wasting your time to browsing codrate's web pages because it has been upgrade always modern coding ways. So, what do you waiting for ?. Try your own.

Copyright 2015 Pride - Company. Design by Esila