Dir is only an example, i could call it Lisa = `../files`, the point is, I can not get the value (../files) in the code in the snippet file.
Let me post the code
let make a document named
Simpledownload
parameters is:
[[!simplefiledownload? &webgroup=`download_1`&`download_2`,&fileFolderURL=`../simplefiledownload/`,
&file=`test.zip`,&file1=`test1.zip`,&file2=`simpledownload.zip`,&file3=``,&file4=``,&file5=``,&file6=``,&file7=``,
&file8=``,&file9=``,&file10=``,&file11=``,&file12=``,&file13=``,&file14=``,&file15=``,
&file16=``,&file17=``,&file18=``,&file19=``,&file20=``]]
-----------------------------------------------------
I make a outside snippet with links like these
$snipFolder = isset($snipFolder)?$snipFolder:’simplefiledownload’;
$snipPath = $modx->config["base_path"].’assets/snippets/’.$snipFolder.’/simplefiledownload.php’;
include_once($snipPath);
or
$snipFolder = isset($snipFolder)?$snipFolder:’simplefiledownload’;
$snipPath = $modx->config["base_path"].’core/components/’.$snipFolder.’/simplefiledownload.php’;
include_once($snipPath);
---------------------------------------------------------------
and the php file in snippet folder is
<?php
//gets inputs from snippet
$webgroup = isset ($webgroup)?$webgroup:$_GET[’webgroup’];
//gets inputs from snippet
$fileFolderURL = isset ($fileFolderURL )?$fileFolderURL :$_GET[’fileFolderURL ’];
# List of downloads, function for compare arrays --- start
function array_isearch($str, $array) {
$found = array();
foreach($array as $k => $v)
if(strtolower($v) == strtolower($str)) $found[] = $k;
return $found;
}
# List of downloads, function for compare arrays --- end
# array for download files --- start
$Array_req = array();
//gets inputs from snippet
$Array_req[] = $file = isset ($file)?$file:$_GET[’file’];
$Array_req[] = $file1 = isset ($file1)?$file1:$_GET[’file1’];
$Array_req[] = $file2 = isset ($file2)?$file2:$_GET[’file2’];
$Array_req[] = $file3 = isset ($file3)?$file3:$_GET[’file3’];
$Array_req[] = $file4 = isset ($file4)?$file4:$_GET[’file4’];
$Array_req[] = $file5 = isset ($file5)?$file5:$_GET[’file5’];
$Array_req[] = $file6 = isset ($file6)?$file6:$_GET[’file6’];
$Array_req[] = $file7 = isset ($file7)?$file7:$_GET[’file7’];
$Array_req[] = $file8 = isset ($file8)?$file8:$_GET[’file8’];
$Array_req[] = $file9 = isset ($file9)?$file9:$_GET[’file9’];
$Array_req[] = $file10 = isset ($file10)?$file10:$_GET[’file10’];
$Array_req[] = $file11 = isset ($file11)?$file11:$_GET[’file11’];
$Array_req[] = $file12 = isset ($file12)?$file12:$_GET[’file12’];
$Array_req[] = $file13 = isset ($file13)?$file13:$_GET[’file13’];
$Array_req[] = $file14 = isset ($file14)?$file14:$_GET[’file14’];
$Array_req[] = $file15 = isset ($file15)?$file15:$_GET[’file15’];
$Array_req[] = $file16 = isset ($file16)?$file16:$_GET[’file16’];
$Array_req[] = $file17 = isset ($file17)?$file17:$_GET[’file17’];
$Array_req[] = $file18 = isset ($file18)?$file18:$_GET[’file18’];
$Array_req[] = $file19 = isset ($file19)?$file19:$_GET[’file19’];
$Array_req[] = $file20 = isset ($file20)?$file20:$_GET[’file20’];
# array for download files --- end
# Get page URL --- start
function curPageURL() {
$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
$port = ($port) ? ’:’.$_SERVER["SERVER_PORT"] : ’’;
$url = ($isHTTPS ? ’https://’ : ’http://’).$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
return $url;
}
# Get page URL --- end
# Download file --- start
$getfilename = isset ($f)?$f:$_GET[’f’];
if ($getfilename){
// set this to the path where your zipped files are located
$filepath = $fileFolderURL.$getfilename;
// a little security
//if(strpos($getfilename, ’..’) !== false || realpath($filepath) != $filepath) die();
if (file_exists($filepath)){
// make sure the browser knows what it’s getting, and what to do with it
header(’Cache-Control: public’);
header(’Content-Type: application/zip’);
header(’Content-Disposition: attachment; filename=’.$getfilename);
readfile($filepath);
die();
} else {
//echo "no file";
die(’Error: File not found.’);
}
}
# Download file --- end
# List of downloads --- start
$area = $modx->isMemberOfWebGroup(array($webgroup));
if ($area === true) {
//echo ’Is a member of the group’;
// open connection to folder
if ($handle = opendir($fileFolderURL)) {
// check if any files in folder
while (false !== ($stored = readdir($handle))) {
//unpack array
$stored = explode(" ", $stored);
//$Array_req = explode("&", $Array_req);
//loop
foreach($stored as $store) {
//compare in function
$results = array_isearch($store,$Array_req);
//loops out result
foreach($results as $key => $result){
//print result in hyperlink
echo "<a href=".curPageURL()."?f=".$Array_req[$result].">".$Array_req[$result]."</a>
";
}//end foreach
}//end foreach
}//end while
}//end opendir
# List of downloads --- end
} else {
echo ’No access for you!’;
}
?>
--------------------------------------------
simplefiledownload folder is outside public_HTML with zip files
--------------------------------------------
It workes in 1.3 and change tags [!!] to these for revolution to this
[[!simplefiledownload? &webgroup=`download_1`&`download_2`,&fileFolderURL=`../simplefiledownload/`,
&file=`test.zip`,&file1=`test1.zip`,&file2=`simpledownload.zip`,&file3=``,&file4=``,&file5=``,&file6=``,&file7=``,
&file8=``,&file9=``,&file10=``,&file11=``,&file12=``,&file13=``,&file14=``,&file15=``,
&file16=``,&file17=``,&file18=``,&file19=``,&file20=``]]
for the test I took out the webgroup security
but values does not show in phpfile
any help would be great
thanks