Skip to content

Disable real file path from being shown

Gamerz edited this page Aug 24, 2011 · 13 revisions

If you want to hide real path to the files you can mask them using connector.php file. Instead of http://localhost/example/path/file.jpg link shown to client, you will get connector.php?cmd=file&target=HASH_TO_FILE_PATH.

The only thing needed to get this is to omit (disable) URL option in connector.php file.

This is a replacement for for the FileURL option in the 1.x (old version).

Example:

<?php
$opts = array(
	'roots' => array(
		array(
			'driver'        => 'LocalFileSystem',   // driver for accessing file system (REQUIRED)
			'path'          => '../files/',         // path to files (REQUIRED)
			// DISABLE 'URL' BY COMMENTING THE FOLLOWING LINE OUT
			// 'URL'        => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
		)
	)
);

.htaccess Option (for advanced users only)

TODO This section must be rewritten to not contain monkey patching of min files

This option is temporarily no longer being supposed by us. We do not advice you to edit the elfinder.min.js as we will be releasing a more efficient way of creating a more user-friendly url path in the next release. Please use the below with caution.

You might find the connector.php?cmd=file&target=HASH_TO_FILE_PATH path a little bit messy for the user. You can clean up the path a little bit by editing your .htaccess file and setting a rewrite URL.

Example .htaccess file:

RewriteEngine on
RewriteBase /

# localhost/view/target (Outputs Files)
RewriteRule ^view/([A-Za-z_0-9-]+)$ connector.php?cmd=file&target=$1

NEXT, OPEN elfinder.min.js:

Find:

(h=c.options.url,h=h+(h.indexOf("?")===-1?"?":"&")+(c.oldAPI?"cmd=open&current="+g.phash:"cmd=file")+"&target="+g.hash)

Replace:

(h=h+(("?")===-1?"?":"")+(c.oldAPI?"cmd=open&current="+g.phash:"view/")+g.hash)

Find:

(n,'<a href="'+f.url(u.hash)+'" target="_blank">'+u.name+"</a>"))

Replace:

(n,'<a href="view/'+u.hash+'" target="_blank">'+u.name+"</a>"))

With the .htaccess option, users will be able to see the url as localhost.com/view/targethash/ when they open a file, instead of the choppy and complicated connector.php?cmd=file&target=targethash

Clone this wiki locally