I tried to copy any dir from my server to client’s pc but i dont know how is possible :S… as example… I have domain.com/Info and I want to copy that folder Info with content so I copy Info and copy in other folder but in my server… but i don’t know, how copy in client’s pc, the sense of my idea is, that if any client want to use my web can to copy that folder in him desktop Any Idea?? my code for copy dir in my server is
function full_copy( $source, $target ) {
if ( is_dir( $source ) ) {
@mkdir( $target );
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) {
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) ) {
full_copy( $Entry, $target . '/' . $entry );
continue;
}
copy( $Entry, $target . '/' . $entry );
}
$d->close();
}else {
copy( $source, $target );
}
}
$s = '/Appserv/www/CpVela/Info';
$des = '/Info/';
full_copy($s,$des);
new EDIT
well I’m Trying to make and download .zip but file.zip that my code creates is empty and damaged :S
my code is this
include "libs/pclzip-2-8-2/pclzip.lib.php";
require("libs/zipfile.php");
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
if(file_exists($destination) && !$overwrite) { return false; }
$valid_files = array();
if(is_array($files)) {
foreach($files as $file) {
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
if(count($valid_files)) {
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
$zip->close();
return file_exists($destination);
}
else
{
return false;
}
}
$array = array();
function full_copy( $source, $target ) {
if ( is_dir( $source ) ) {
@mkdir( $target );
//$archivo = new zipfile();
$archive = new PclZip('zipfile.zip');
$d = dir( $source );
while ( FALSE !== ( $entry = $d->read() ) ) {
if ( $entry == '.' || $entry == '..' ) {
continue;
}
$Entry = $source . '/' . $entry;
if ( is_dir( $Entry ) ) {
full_copy( $Entry, $target . '/' . $entry );
continue;
}
if(count($array) > 1 ){
array_push($array, $Entry);
}else{
$array[0] = $Entry;
}
// $archivo->add_file($Entry,$Entry);
//$v_list = $archive->add($Entry, PCLZIP_OPT_REMOVE_PATH, 'dev');
//copy( $Entry, $target . '/' . $entry );
}
$d->close();
}else {
copy( $source, $target );
}
}
$s = '/Appserv/www/CpVela/Info';
$des = '/Appserv/www/CpVela/';
full_copy($s,$des);
create_zip($array,'zipfile.zip');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=zipfile.zip");
echo $zipfile->file();
You can’t do this from a web browser. PHP runs on the server where the web page executes, and nowhere else.
If you want to allow the client to do this, you’d need to use another tool, or another language. Or just make a zip file that he can download.