simple-file-manager icon indicating copy to clipboard operation
simple-file-manager copied to clipboard

how to change the working directory

Open danielcorrea opened this issue 11 years ago • 14 comments

how to change the working directory

I have the following structure: / / admin - here's the simple-file-manager / images - here are the files it should manage.

Where do I change the working path of the script?

danielcorrea avatar Mar 11 '14 16:03 danielcorrea

I didn't consider this use case. I'll look into making this possible.

On Tue, Mar 11, 2014 at 12:33 PM, Daniel Correa [email protected]:

how to change the working directory

I have the following structure: / / admin - here's the simple-file-manager / images - here are the files it should manage.

Where do I change the working path of the script?

— Reply to this email directly or view it on GitHubhttps://github.com/jcampbell1/simple-file-manager/issues/2 .

jcampbell1 avatar Mar 11 '14 16:03 jcampbell1

I'm also interested in this issue.

andreibordeianu avatar May 04 '14 22:05 andreibordeianu

I'm interested as well, it would also be cool to view multiple working directories at once.

jaredjones avatar Apr 22 '15 20:04 jaredjones

nice job ! it would be nice to be able to call this script as an object . for example include '/path/to/index.php' $FileManager = new FileManager('path to directory of uploads'); print $FileManager->create();

rezatbaher avatar Feb 26 '16 09:02 rezatbaher

chdir() seems to do the trick: http://php.net/manual/en/function.chdir.php

PHP File Manager in /www and Files (to manage) in /www/images

chdir('images'); or chdir('/www/images') is al it takes.

EwoutV6 avatar Mar 02 '17 12:03 EwoutV6

Hello! News about this feature? Thanks

mungle avatar Mar 08 '17 11:03 mungle

you can change the root folder in the program itself. You have to change it in 2 parts .

1: upload part.

foreach($disallowed_extensions as $ext) if(preg_match(sprintf('/.%s$/',preg_quote($ext)), $_FILES['file_data']['name'])) err(403,"Files of this type are not allowed."); //echo $_FILES['file_data']['name']; var_dump(move_uploaded_file($_FILES['file_data']['tmp_name'], "NEWROOT/".$file.'/'.$_FILES['file_data']['name'])); exit; }

2 : view part . if($_GET['do'] == 'list') { if (is_dir($file)) { $directory = $file**."/NEWROOT"**; // Change NEWROOT to the file you require . $result = []; $files = array_diff(scandir($directory), ['.','..']); foreach($files as $entry) if($entry !== basename(FILE)) { $i = $directory . '/' . $entry; $stat = stat($i); $result[] = [ 'mtime' => $stat['mtime'], 'size' => $stat['size'], 'name' => basename($i), 'path' => preg_replace('@^./@', '', $i), 'is_dir' => is_dir($i), 'is_deleteable' => $allow_delete && ((!is_dir($i) && is_writable($directory)) || (is_dir($i) && is_writable($directory) && is_recursively_deleteable($i))), 'is_readable' => is_readable($i), 'is_writable' => is_writable($i), 'is_executable' => is_executable($i), ]; } }

harikrishnanr994 avatar Mar 31 '17 14:03 harikrishnanr994

I was able to use the chdir() trick mentioned by EwoutV6 and got this working, by putting it right before the meat of the directory logic (if($_GET['do'] == 'list') {...). I also replaced $tmp_dir, but it looks like it didn't matter.

It would be cool if the Simple File Manager code could take in a source path as a config parameter at the beginning of the code, and let us simply set it cleanly that way. :) Otherwise, very cool and useful script!

bigicoin avatar May 27 '17 23:05 bigicoin

Please support this feature +1

johnwmail avatar May 28 '17 09:05 johnwmail

This is a bit tricky because it assumes the files are addressable by the web server. There isn't a easy option to add that will:

  1. work as expected in most cases
  2. Not introduce a security issue

For instance, if people want to serve the files in /home/person/photos/ then the photos won't be served by the web server if I add that option.

Creating a symlink on the server may solve many cases.

jcampbell1 avatar Oct 24 '19 18:10 jcampbell1

nice job ! it would be nice to be able to call this script as an object . for example include '/path/to/index.php' $FileManager = new FileManager('path to directory of uploads'); print $FileManager->create();

how to do this?

murulimadhav avatar Jun 28 '20 06:06 murulimadhav

Look in the commits section. Someone has committed code for this setting, but it hasn't been merged yet. Just use the file from that section and it works.

flattery103 avatar Jun 14 '21 00:06 flattery103

https://github.com/jcampbell1/simple-file-manager/pull/113/commits/241239382182c31d2296029e29d34d1806f87fce

abdes-zakari avatar Nov 05 '21 14:11 abdes-zakari

I had changed the "$tmp_dir", point it to new root, it work for me over a year.

johnwmail avatar Nov 06 '21 03:11 johnwmail