Dear friends
i have a OpenSOURCE software which i developed in php. that is not working in properly. this code is used tio downlaod the zip file..
<?PHP
/**
* export object as a zipped folder with
* xml + binary objects (images etc ...)
*
*/
// define plugin name
$ipath->plugins['export']['object']['zip']->title = "export object as zip file...............";
$ipath->plugins['export']['object']['zip']->url = "object/export";
function object_export(){
global $ipath;
$id = $ipath->ARGV['id'];
if( $id<0 )
return error_message( "no such object" );
$obj = object_factory($id);
if( !is_object($obj) OR !$obj->getPerm() ){
return access_denied();
} else {
$exp = new ipathExport_object($id);
if( $exp->prepare() ){
$fn = basename( $exp->getFileName());
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
header("Content-Type: application/octetstream");
ini_set( 'zlib.output_compression','Off' );
} else {
header( "Content-Type: ".$exp->getMimeType()."; charset=UTF-8" );
}
header( "Content-Length: ".filesize($exp->getFileName()) );
header( "Content-disposition: ".
(strpos($HTTP_USER_AGENT,"MSIE 5.5")?"" :"attachment; ").
"filename=\"" . $fn. "\"" );
header( "Pragma: public" );
header( "Expires: 0" );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Cache-Control: public" );
header( "Content-Description: File Transfer" );
header( "Content-Transfer-Encoding: binary" );
readfile_chunked( $exp->getFileName() );
$exp->cleanUp();
exit;
}
return error_message("export failed");
}
}
class iPathExport_object{
function __construct($tmp=-1){
if(is_object($tmp) ){
$this->obj = $tmp;
} elseif( is_numeric($tmp) AND $tmp>0 ){
$this->obj = object_factory($tmp);
}
}
function prepare(){
global $ipath;
if( !$this->obj ){
$this->error = "no object specified";
return false;
}
$exp_dir = $ipath->conf['data_dir']."/tmp/o".$this->obj->getVal("id")."_".trim_filename($this->obj->getTitle());
mkdir( $exp_dir );
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
$this->obj->getXML(OBJECTXML_RECURSE | OBJECTXML_EXPORT);
$fp = fopen($exp_dir."/object.xml", "w+");
fwrite( $fp, $xml );
fclose($fp);
$dom = DOMDocument::LoadXML($xml);
// print_r($dom);
$children = $dom->getElementsByTagName("object");
echo memory_get_usage($children);
foreach( $children as $child ){
$c_id = $child->getAttribute("id");
if( $id != $c_id ){
$c_object = object_factory($c_id);
if( $c_object->binaryPath() ){
copy( $c_object->binaryPath(),
$exp_dir."/".$c_id."_".$c_object->binaryName() );
$a=$exp_dir."/".$c_id."_".$c_object->binaryName();
}
}
}
// hard wired copy of icons - this must become
// dynamic some time:
mkdir( $exp_dir."/images/" );
if( !file_exists("images/folder.png") )
die( "no images/folder.png" );
copy( "./images/folder.png", $exp_dir."/images/folder.png" );
copy( "./images/document.png", $exp_dir."/images/document.png" );
$xslfile = "modules/io/xsl/object.xsl";
if( file_exists($xslfile) ){
$xsl = file_get_contents($xslfile);
$html = xml2html( $this->obj->getXML(OBJECTXML_RECURSE | OBJECTXML_COMMENTS), $xsl );
file_put_contents( $exp_dir."/preview.html", $html );
// print "<hr>$html<hr>";
}
// create the zip file
$this->zip_file = $exp_dir.".zip";
// this line is specific for UNIX OS - will not work on Windows
// and may not work on some hosting servers.
/*
system( "cd ".$ipath->conf['data_dir']."/tmp; "."zip -r ".basename($this->zip_file)." ".basename($exp_dir). " > /dev/null");
system( "rm -r $exp_dir" );
*/
// check encryption
if( $this->obj->getGroup()->getInfoVal("gpg_export")==1 OR
$ipath->user->getInfoVal("gpgencrypt")==1 ){
if( strlen( $ipath->user->getInfoVal("gpgkey") )<10 ){
// must encrypt but user has no key
$this->_error = "user has no GPG key";
return false;
} else {
if( ipath_gpgFileEncrypt( $this->zip_file, $this->zip_file.".gpg" ) ){
$this->zip_file = $this->zip_file.".gpg";
$this->_mimetype = "application/pgp-encrypted";
return true;
} else {
$this->_error = "encryption failed.";
return false;
}
}
}
return true;
}
function getFileName(){
return $this->zip_file;
}
function getMimeType(){
if( $this->_mimetype )
return $this->_mimetype;
// return "application/x-zip";
}
function cleanUp(){
unlink( $this->zip_file );
}
}
?>
Regards
Dodo
code does not working
Moderator: General Moderators