In any case, I continued work on my CMS and decided to forget about this issue for the time being. Fast forward a year to just a couple of weeks ago: I decided to look around again and see if anything was available. I even searched the envato market in hopes of finding something to purchase. Alas, no luck. In 2015, we are still sorely in need of a decent file manager (at least for non-PHP developers that is). So I decided to take another crack at Responsive File Manager - firstly to see how complex it was and if I should attempt to rewrite it in JQuery.
It was at this time I had a thought; .NET now has compilers for Ruby (Iron Ruby), Python (Iron Python) and so forth... I wondered if there was something for PHP. A few minutes of Googling later and bingo! I discovered Phalanger - the PHP compiler for .NET. I spent the next few days struggling with various issues to make it work just right, but I am happy to say, I now have Responsive File Manager working very well within my ASP.NET MVC site. Follow the steps below and you can too...
Installation & Configuration
- First of all, you should download Responsive File Manager, which you can do so from the GitHub page here: https://github.com/trippo/ResponsiveFilemanager
- Extract the files and copy the filemanager folder to the root of your site.
Note: If you try to copy it anywhere else, it seems to return incorrect relative URLs.
- Download Phalanger 4.0 from the following link: https://github.com/DEVSENSE/Phalanger
- Open the source code and find the function
imagecolorsforindex() in /Extensions/Gd2/PhpGd.cs. You will notice that it is not implemented. Copy the code from this pull request: https://github.com/DEVSENSE/Phalanger/pull/19/files. Here it is below to save you searching:
public static PhpArray imagecolorsforindex(PhpResource im, int col)
var im1 = (PhpGdImageResource)im;
var arr = new PhpArray();
var entries = im1.Image.Palette.Entries;
if (entries.Length > 0)
color = entries[col];
color = Color.FromArgb(col);
arr["red"] = (int)color.R;
arr["green"] = (int)color.G;
arr["blue"] = (int)color.B;
arr["alpha"] = (int)color.A;
This prevents a particular compiler error. If I recall correctly, it's used when handling bitmap files.
- Build the source code in release mode and reference the DLLs from your project. Note that you will need to have opened Visual Studio with Administrator privileges or you will get build errors. Also note, I have not yet determined exactly which DLLs are required and which can be ignored. You can definitely ignore the SQL and Zip DLLs though.
- You will need the following added to your web.config file:
<section name="phpNet" type="PHP.Core.ConfigurationSectionHandler,
PhpNetCore, Version=126.96.36.199, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71" />
<add assembly="PhpNetClassLibrary, Version=188.8.131.52,
Culture=neutral, PublicKeyToken=4af37afe3cde05fb" section="bcl" />
<add assembly="PhpNetMbstring, Version=184.108.40.206,
Culture=neutral, PublicKeyToken=2771987119c16a03" />
<add assembly="PhpNetGd2, Version=220.127.116.11,
Culture=neutral, PublicKeyToken=2771987119c16a03" />
<add name="Phalanger" path="*.php"
verb="*" type="PHP.Core.RequestHandler, PhpNetCore,
Version=18.104.22.168, Culture=neutral, PublicKeyToken=0a8e8c4c76728c71"
resourcetype="Unspecified" precondition="integratedMode" />
<probing privatepath="Phalanger" />
- To prevent various errors, find and remove all
exit; commands in the file manager's .php files. Note: I have no experience with PHP so perhaps I should have taken another approach to solving this, but so far I have not seen any bad side effects of doing so. My guess is these
exit; keywords are not needed when using Phalanger.
- There were two functions being called by the file manager which are not yet implemented by Phalanger. The first of these is the following:
ini_set('memory_limit' .... This appears in the
image_check_memory_usage function on line 567 of /filemanager/include/utils.php. This function is called when the file manager is creating thumbnails. Apparently, this is not required when using Phalanger, since simply returning
true at the top of the function works just fine.
- Again in utils.php, we want to change one more thing: on Windows (or at least on my machine), the
rename_folder function fails with a permissions exception when it calls PHP's
rename function. Oddly, the
rename function only seems to fail when renaming folders; files are fine. So, replace the last line:
return rename($old_path, $new_path);
if (!mkdir($new_path, 0755, true))
rcopy($old_path, $new_path, true);
And that works fine.
- Find the
resizeImage function near the top of the file in /filemanager/include/php_image_magician.php. At the end of this function, comment out the following 3 lines:
if ($sharpen && in_array($this->fileExtension, $this->sharpenArray))
This needs to be commented out because the
sharpen() function makes a call to
imageconvolution which is something not yet supported by Phalanger. Luckily for us, ignoring this doesn't seem to make any noticeable difference.
That should be all you need to get started.
So far pretty much everything seems to be working well, but I will note that I didn't bother checking the Aviary image editing features because I have no need of them at this point. It is likely there will be a few issues to fix with that too. I simply turned off that feature in the /config/config.php file by setting
Final Thoughts and Conclusion
It may be interesting to note that I originally believed I would need a PHP view engine, such as the one on Codeplex at https://phpviewengine.codeplex.com/ which makes use of Phalanger as well. To my satisfaction, this is not the case; there is absolutely no need whatsoever for a PHP view engine; you can continue using your .cshtml files as you normally would. However, I do find the thought of adding a PHP view engine alongside the Razor one to be very intriguing. Those more interested should have some fun with that.
Hats off to the Phalanger team and to Alberto Peripolli for his excellent file manager. Now us .NET developers can have the best file manager in our MVC applications (likely Web Forms would work just as well too). If you have any comments or any suggestions on improving upon my work, please do share with the rest of us. My hope is we'll all eventually end up with a perfect implementation of the Responsive File Manager in ASP.NET.