0

So I am trying to view the content in subfolders $fileinfo from a root folder (00skap) which is on network folder in "fs1". PHP error log is not updating any warnings and sometimes it does which is weird. So I can't provide any errors as of now from the PHP error log.

This is my code:

<!DOCTYPE html>
<html>
<body>
<h1>Images</h1>
</body>

<?php 

$dirs = '\\\fs1\images\00skap';

$dir = new DirectoryIterator($dirs);
foreach ($dir as $fileinfo) {
    if ($fileinfo->isDir() && !$fileinfo->isDot()) {
         $fileinfo->getFilename().'<br>';

 echo "<font color='red'><a href=\\fs1\images\00skap/$fileinfo\"          style='color:#f9c539' >$fileinfo</a></br></font>";
         
        //echo  "<button onclick=\"location.href='/////fs1/images/00skap/$fileinfo'\">$fileinfo</button><br>";

         
    }
    
}
         

I have tried with those two "echo" options. The first one I get a 404 - File or directory not found. The other one only loads the page a long time and later crashes. I'm positive that I have the right location and permissions can't be a problem.

This is how I view the subfolders before I try to view the content inside them: Main Page

I know I might have a syntax error here or something obvious but I've looked at this now for several hours.

Thank You!

P.S. I'm browsing on Firefox but I can use other options.

Update

"Config Error: Cannot read configuration file due to insufficient permissions." Found the "web.config" file that says:<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <remove name="FastCGI" /> <add name="FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" resourceType="File" /> </handlers> </system.webServer> </configuration>

Gummi
  • 37
  • 6
  • Could also be a problem that can't be solved with just the code above. But any hints or where I could start looking would be amazing! The thing is that I can't move the folder, duplicate it :/ – Gummi Jun 13 '23 at 10:41
  • Did you create an alias for this in your Virtual Host or base config. Remember, Apache will protect all folders outside the DocumentRoot unless expressly give access to them – RiggsFolly Jun 13 '23 at 11:38
  • I'm not really sure how to do that since i'm using a local IIS @RiggsFolly ? Could URL Rewrite be the solution perhaps? – Gummi Jun 13 '23 at 11:48
  • Maybe [this will give some clues](https://stackoverflow.com/questions/14611015/iis7-accessing-network-share), at least on what to research. I am not familiar with IIS so cannot really help much – RiggsFolly Jun 13 '23 at 11:52
  • Thanks! Also I found that the URL in web browser looks like this on "00skap": /fs1/images�skap/20000-20999" @RiggsFolly . Is this just how it displays it or could this be the problem? – Gummi Jun 13 '23 at 11:57
  • In a double-quoted string, `\00` will kick in [octal notation](https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double) because of the leading backslash and zero, so that is asking for zero byte string, https://3v4l.org/joPK3, which you are seeing as � which is the Unicode replacement character – Chris Haas Jun 13 '23 at 12:18
  • Ah, didn't know that, thanks! But that would not be a problem then, right? @ChrisHaas – Gummi Jun 13 '23 at 12:25
  • To be honest, I didn't read much of the rest of your question, sorry, that just stood out to me. I haven't dealt with IIS and PHP in a very long time, so unfortunately I'm not going to be much help here, either. – Chris Haas Jun 13 '23 at 12:28
  • 1. Start by writing a static HTML page that contains just the basic elements to implement the features you want. This allows you to know what are the valid HTML syntax to use 2. Replace part of the static page with PHP code so that on server side the right HTML elements can be generated. In your case, the PHP code shows trivial mistakes (like ` – Lex Li Jun 13 '23 at 22:05
  • @LexLi Since I have about 140 subfolder to list up in main page (with different names of course), is it not the easiest and shortest way to write the PHP/HTML code as I've done? The wrong syntax in (' – Gummi Jun 14 '23 at 05:13
  • Ok, if think about IIS configuration, this error may be due to path or permission issues, or some modules are missing. What is your actual web.config path? Make the file accessible to the IIS_IUSRS group. When the group is not available, replace IIS_IUSRS by ComputerName\IIS_IUSRS. Which modules are referenced in the configuration file? – TengFeiXie Jun 14 '23 at 06:05
  • The thing is, (i'm not entire sure) but I can't find the web.config file as mentioned in the update above. The path it says is "\\?\UNC\fs1\images\web.config". Should I be able to find the config file through IIS? Because with that path above, I have no idea how to find it. If it even exists. @TengFeiXie – Gummi Jun 14 '23 at 06:13
  • The web.config file should be in the path where your site is deployed. I'm not familiar with UNC paths. You can also find the configuration file path under the **configuration editor** of your site. – TengFeiXie Jun 15 '23 at 07:01
  • I did alot of changes so I barely remember everything, but somehow the web.config has been created now and it's where you mentioned @TengFeiXie . I checked and IUSR group have access to it already. This is in web.config: ` ` – Gummi Jun 15 '23 at 12:05
  • Hi, have you tried creating a new demo and deploying to IIS for testing? Test to see if the same error occurs. I think this problem has troubled you a long time, but there are some factors that need to be ruled out but not been. It is usually a permission or path issue in IIS configuration. Since path and permissions are normal, then you need to check whether your code or deployment process is correct. The whole troubleshooting may require many tests, but it is essential. In addition, base on your web.config, it is probably not an error caused by referencing an uninstalled modules. – TengFeiXie Jun 16 '23 at 10:21
  • Thank you for not giving up on this problem and helping me out! I have about 3 other web sites on IIS which works fine but none of them involves listing up subfolders of some kind. So I think you are hinting in the right direction, something is wrong with the setup/configuration of this web site. I think I'm going to try and create a new web site for this and go through the setup process in detail on IIS next week since another problem on another website has arrived which has higher priority. I will come with an update. Thanks again! @TengFeiXie – Gummi Jun 16 '23 at 11:11

1 Answers1

1

Not quite at my end goal with this project but atleast I got the problem fixed. Seems like the best way to access a network folder and it's content is to create a Virtual Directory in IIS and then refer to it in the PHP code.

I had access to the network folder but I only could list up the root folders content. Everything went smooth after I created the Virtual Directory.

Also rewrote the code with some help:


    $selectedDir = isset($_GET["dir"]) ? $_GET["dir"] : "";
//echo $selectedDir;
echo '<h1> '.$selectedDir.' </h1>';
$dirs = "\\\\server\images\\moreimages/$selectedDir";


$dir = new DirectoryIterator($dirs);
foreach ($dir as $fileinfo) {
    if ($fileinfo->isDir() && !$fileinfo->isDot()) {
        $directorypath = $selectedDir."/".$fileinfo->getFilename();
        echo "<a href='?dir=".$directorypath."'>".$fileinfo->getFilename()."</a><br>";
        
    }
Gummi
  • 37
  • 6