File "create.php"
Full Path: /home/analogde/www/filetypes/zip/create.php
File size: 5.91 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/***************************************************************
* Copyright notice
*
* (c) 2003-2004 Tobias Bender (tobias@phpXplorer.org)
* All rights reserved
*
* This script is part of the phpXplorer project. The phpXplorer project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require(dirname(dirname(__FILE__)) . "/defaultActionHead.php");
require($GC_other_Path . "/zip.lib.php");
$fileName = getRequestVar("fileName");
$fileList = $HTTP_POST_VARS['fileList'];
$submitAction = getRequestVar("submitAction");
$submitOverwrite = getRequestVar("submitOverwrite");
if(!(strpos($fileName, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
$pInfo = checkFilePermissions($fileName);
if(!$pInfo["allowOpen"] or !$pInfo["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
$archive = new zipfile();
if($submitAction != ""){
$fileList = explode(",", $fileList);
foreach($fileList as $file){
if(!(strpos($file, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
$pInfoFile = checkFilePermissions($file);
if(!$pInfoFile["allowOpen"] or !$pInfoFile["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
if(is_dir($currentDir . "/" . $file)){
$archive->addTree($currentDir . "/" . $file, $currentDir . "/");
}else{
$archive->addFile($currentDir . "/" . $file, $file);
}
}
$n = strpos($fileName, ".zip") === FALSE ? $currentDir . "/" . $fileName . ".zip" : $currentDir . "/" . $fileName;
if($submitAction == "download"){
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . basename($n));
echo $archive->file();
die;
}else{
$bCreateFile = false;
if(file_exists($n)){
if($submitOverwrite == ""){
$submitOverwrite = "overwrite";
}else{
if($submitOverwrite == "overwriteConfirm")
$bCreateFile = true;
}
}else{
$bCreateFile = true;
}
if($bCreateFile)
$archive->writeFile($n);
}
}
?>
<html>
<head>
<title><?php echo $PXP_languages[$PXP_language]["createZIP"] ?></title>
<style type="text/css">
<!--
-->
</style>
<link rel="stylesheet" type="text/css" href="<?php echo $PXP_url ?>/styles/<?php echo $PXP_style ?>/main.css">
<script language="JavaScript" type="text/javascript">
<!--
var fL = new Array()
var el = opener.document.frm1.elements
function validate(){
var f = document.frm1
if(fL.length == 0){
alert("<?php echo $PXP_languages[$PXP_language]['noFilesSelected'] ?>");
return
}
if(!f.fileName.value != ""){
alert("<?php echo $PXP_languages[$PXP_language]['pleaseInsertValue'] ?>")
f.fileName.focus()
return false
}
return true
}
function send(a, overwrite){
getSelected()
if(!validate())
return false
if(a != "download")
switchButton()
var f = document.frm1
f.submitAction.value = a
if(overwrite)
f.submitOverwrite.value = "overwriteConfirm"
f.submit()
}
function switchButton(){
var f = document.frm1
f.btnCreate.disabled = !f.btnCreate.disabled
f.btnCreateAndEdit.disabled = !f.btnCreateAndEdit.disabled
f.btnCancel.disabled = !f.btnCancel.disabled
}
function getSelected(){
for(var e = 0; e < el.length; e++)
if(el[e].name == "fileSelection[]" || el[e].name == "folderSelection[]")
if(el[e].checked)
fL[fL.length] = el[e].value
document.frm1.fileList.value = fL.join(",")
}
function init(){
<?php
if($submitOverwrite == "overwrite"){
echo "if(confirm('" . $PXP_languages[$PXP_language]["allowOverwrite"] . "?')){\r\n";
echo " send('" . $submitAction . "', true)\r\n";
echo "}else{\r\n";
echo " document.frm1.fileName.focus()\r\n";
echo " document.frm1.fileName.select()\r\n";
echo "}\r\n";
}else{
switch($submitAction){
case "create":
echo "opener.refreshDir()\r\n";
echo "window.close()\r\n";
break;
case "download":
echo "window.close()\r\n";
break;
case "":
echo "document.frm1.fileName.focus()\r\n";
echo "document.frm1.fileName.select()\r\n";
break;
}
}
?>
}
//-->
</script>
</head>
<body onLoad="init()">
<form name="frm1" action="./create.php" method="post">
<input type="hidden" name="currentDir" value="<?php echo $currentDir ?>">
<input type="hidden" name="shareId" value="<?php echo $shareId ?>">
<input type="hidden" name="submitAction" value="<?php echo $submitAction ?>">
<input type="hidden" name="submitOverwrite" value="<?php echo $submitOverwrite ?>">
<input type="hidden" name="fileList" value="">
<?php
if($errors != "")
echo "<span class=\"error\">$errors</span>";
?>
<?php echo $PXP_languages[$PXP_language]["createZIP"] ?>
<br><br>
<table>
<tr>
<td>
<?php echo $PXP_languages[$PXP_language]["name"] ?>
</td>
<td>
<input type="text" name="fileName" size="30" value="<?php echo $fileName ?>"><br>
</td>
</tr>
<tr>
<td> </td>
<td>
<br><br>
<input type="button" name="btnCreate" onClick="send('create')" value="<?php echo $PXP_languages[$PXP_language]['create'] ?>">
<input type="button" name="btnCreateAndEdit" onClick="send('download')" value="<?php echo $PXP_languages[$PXP_language]['download'] ?>">
<input type="button" name="btnCancel" onClick="window.close()" value="<?php echo $PXP_languages[$PXP_language]['cancel'] ?>">
</td>
</tr>
</table>
</form>
</body>
</html>