Jump to content

elFinder want to post a value to connector.php


ztimer

Recommended Posts

Hi. What i would like is to post a user_id value to connector.php to make the home and root directory based on the value i need at the moment.

 

i have a page that shows user details and i have a value $user_id = $_GET['selected_worker'];

 

		<!-- elFinder initialization (REQUIRED) -->
	<script type="text/javascript" charset="utf-8">
		$().ready(function() {
			var elf = $('#elfinder').elfinder({
			 	lang: 'ru',	// language (OPTIONAL)
				url : 'php/connector.php',  // connector URL (REQUIRED)
				directory : 'files'
			}).elfinder('instance');			
		});
	</script>

 

the actual connector.php

<?php

error_reporting(0); // Set E_ALL for debuging

include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';
// Required for MySQL storage connector
//include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php';

/**
* Simple function to demonstrate how to control file access using "accessControl" callback.
* This method will disable accessing files/folders starting from  '.' (dot)
*
* @param  string  $attr  attribute name (read|write|locked|hidden)
* @param  string  $path  file path relative to volume root directory started with directory separator
* @return bool
**/
function access($attr, $path, $data, $volume) {
return strpos(basename($path), '.') === 0   // if file/folder begins with '.' (dot)
	? !($attr == 'read' || $attr == 'write')  // set read+write to false, other (locked+hidden) set to true
	: ($attr == 'read' || $attr == 'write');  // else set read+write to true, locked+hidden to false
}

// This works when manually adding 
$user_id= "323"; 

// Not working when 
$user_id= $_GET['selected_worker'];


$opts = array(
// 'debug' => true,
'roots' => array(
	array(
		'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
		'path'          => '../'.$user_id.'/',         // path to files (REQUIRED)
		'URL'           => dirname($_SERVER['PHP_SELF']) . '/../'.$user_id.'/', // URL to files (REQUIRED)
		'accessControl' => 'access'             // disable and hide dot starting files (OPTIONAL)
	)
)
);

// run elFinder
$connector = new elFinderConnector(new elFinder($opts));
$connector->run();

 

How can i post a value to the connector.php

 

Any ideas ?

Please help.

 

Link to comment
Share on other sites

The most obvious answer to me is to send them as get variables.

<!-- elFinder initialization (REQUIRED) -->
	<script type="text/javascript" charset="utf-8">
		$().ready(function() {
			var elf = $('#elfinder').elfinder({
			 	lang: 'ru',	// language (OPTIONAL)
				url : 'php/connector.php?id=<?php echo $user_id; ?>',  // connector URL (REQUIRED)
				directory : 'files'
			}).elfinder('instance');			
		});
	</script>

 

Then in connector.php just use $_get['id'].

Link to comment
Share on other sites

Hi. Thank you for your answer. This way of using the url to post was the first thing i tried but no luck. It just was not able to get the info. So i managed to make another post using

the actual script itself. Then i got it to work. And for others out there i will post my findings. Hope it helps somebody.

 

		<?php $customdirectory = "../files/22"; ?>

	<!-- elFinder initialization (REQUIRED) -->
	<script type="text/javascript">
	    $().ready(function() {
	        var elf = $('#elfinder').elfinder({
	            url : 'php/connector.php',
	            customData : { startPath : "<?php echo $customdirectory ?>" },
	            rememberLastDir : false
	        }).elfinder('instance');
	    });
	</script>

 

The connector.php

<?php

error_reporting(0); // Set E_ALL for debuging

include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php';
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php';

function access($attr, $path, $data, $volume) {
return strpos(basename($path), '.') === 0   // if file/folder begins with '.' (dot)
	? !($attr == 'read' || $attr == 'write')  // set read+write to false, other (locked+hidden) set to true
	: ($attr == 'read' || $attr == 'write');  // else set read+write to true, locked+hidden to false
}

$filePath = '../files'; $startPath = $filePath;
if(isset($_GET['startPath']) && !empty($_GET['startPath'])) { $startPath .= '/'.$_GET['startPath']; }

$opts = array(
// 'debug' => true,
'roots' => array(
	array(
		'driver'        => 'LocalFileSystem',
		'path'          => $startPath,
		'startPath' 		=> $startPath,
		'accessControl' => 'access'
	)
)
);

$connector = new elFinderConnector(new elFinder($opts));
$connector->run();

?>

 

 

The most obvious answer to me is to send them as get variables.

<!-- elFinder initialization (REQUIRED) -->
	<script type="text/javascript" charset="utf-8">
		$().ready(function() {
			var elf = $('#elfinder').elfinder({
			 	lang: 'ru',	// language (OPTIONAL)
				url : 'php/connector.php?id=<?php echo $user_id; ?>',  // connector URL (REQUIRED)
				directory : 'files'
			}).elfinder('instance');			
		});
	</script>

 

Then in connector.php just use $_get['id'].

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.