尝试访问网络上根文件夹中的子文件夹并查看内容

huangapple go评论67阅读模式
英文:

Trying to access subfolders and view the content from root folder on a network

问题

I'll translate the code portion for you:

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

<?php 

$dirs = '\\\\fs1\\images\
<!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>";
         
    }
    
}
skap';
$dir = new DirectoryIterator($dirs); foreach ($dir as $fileinfo) { if ($fileinfo->isDir() && !$fileinfo->isDot()) { $fileinfo->getFilename().'<br>'; echo "<font color='red'><a href='\\fs1\\images\
<!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>";
         
    }
    
}
skap/$fileinfo'
style='color:#f9c539' >$fileinfo</a></br></font>";
//echo "<button onclick=\"location.href='/////fs1/images/00skap/$fileinfo'\">$fileinfo</button><br>"; } }

Please note that the code you provided seems to be intended for a web page to list subfolders in a directory. If you have issues with 404 errors or page crashes, you may want to check the paths and permissions carefully as mentioned in your question.

Is there anything else you need?

英文:

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:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;Images&lt;/h1&gt;
&lt;/body&gt;

&lt;?php 

$dirs = &#39;\\\fs1\images
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;Images&lt;/h1&gt;
&lt;/body&gt;
&lt;?php 
$dirs = &#39;\\\fs1\images\00skap&#39;;
$dir = new DirectoryIterator($dirs);
foreach ($dir as $fileinfo) {
if ($fileinfo-&gt;isDir() &amp;&amp; !$fileinfo-&gt;isDot()) {
$fileinfo-&gt;getFilename().&#39;&lt;br&gt;&#39;;
echo &quot;&lt;font color=&#39;red&#39;&gt;&lt;a href=\\fs1\images\00skap/$fileinfo\&quot;          style=&#39;color:#f9c539&#39; &gt;$fileinfo&lt;/a&gt;&lt;/br&gt;&lt;/font&gt;&quot;;
//echo  &quot;&lt;button onclick=\&quot;location.href=&#39;/////fs1/images/00skap/$fileinfo&#39;\&quot;&gt;$fileinfo&lt;/button&gt;&lt;br&gt;&quot;;
}
}
skap&#39;; $dir = new DirectoryIterator($dirs); foreach ($dir as $fileinfo) { if ($fileinfo-&gt;isDir() &amp;&amp; !$fileinfo-&gt;isDot()) { $fileinfo-&gt;getFilename().&#39;&lt;br&gt;&#39;; echo &quot;&lt;font color=&#39;red&#39;&gt;&lt;a href=\\fs1\images
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;Images&lt;/h1&gt;
&lt;/body&gt;
&lt;?php 
$dirs = &#39;\\\fs1\images\00skap&#39;;
$dir = new DirectoryIterator($dirs);
foreach ($dir as $fileinfo) {
if ($fileinfo-&gt;isDir() &amp;&amp; !$fileinfo-&gt;isDot()) {
$fileinfo-&gt;getFilename().&#39;&lt;br&gt;&#39;;
echo &quot;&lt;font color=&#39;red&#39;&gt;&lt;a href=\\fs1\images\00skap/$fileinfo\&quot;          style=&#39;color:#f9c539&#39; &gt;$fileinfo&lt;/a&gt;&lt;/br&gt;&lt;/font&gt;&quot;;
//echo  &quot;&lt;button onclick=\&quot;location.href=&#39;/////fs1/images/00skap/$fileinfo&#39;\&quot;&gt;$fileinfo&lt;/button&gt;&lt;br&gt;&quot;;
}
}
skap/$fileinfo\&quot; style=&#39;color:#f9c539&#39; &gt;$fileinfo&lt;/a&gt;&lt;/br&gt;&lt;/font&gt;&quot;; //echo &quot;&lt;button onclick=\&quot;location.href=&#39;/////fs1/images/00skap/$fileinfo&#39;\&quot;&gt;$fileinfo&lt;/button&gt;&lt;br&gt;&quot;; } }

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:
尝试访问网络上根文件夹中的子文件夹并查看内容

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:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;configuration&gt; &lt;system.webServer&gt; &lt;handlers&gt; &lt;remove name=&quot;FastCGI&quot; /&gt; &lt;add name=&quot;FastCGI&quot; path=&quot;*.php&quot; verb=&quot;*&quot; modules=&quot;FastCgiModule&quot; scriptProcessor=&quot;C:\PHP\php-cgi.exe&quot; resourceType=&quot;File&quot; /&gt; &lt;/handlers&gt; &lt;/system.webServer&gt; &lt;/configuration&gt;

答案1

得分: 1

不过我还没有达到这个项目的最终目标,但至少我解决了问题。似乎访问网络文件夹及其内容的最佳方式是在IIS中创建虚拟目录,然后在PHP代码中引用它。

我能够访问网络文件夹,但只能列出根文件夹的内容。在创建虚拟目录后,一切都顺利进行。

还进行了一些代码重写,得到了一些帮助:

$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>";
    }
}
英文:

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[&quot;dir&quot;]) ? $_GET[&quot;dir&quot;] : &quot;&quot;;
//echo $selectedDir;
echo &#39;&lt;h1&gt; &#39;.$selectedDir.&#39; &lt;/h1&gt;&#39;;
$dirs = &quot;\\\\server\images\\moreimages/$selectedDir&quot;;


$dir = new DirectoryIterator($dirs);
foreach ($dir as $fileinfo) {
    if ($fileinfo-&gt;isDir() &amp;&amp; !$fileinfo-&gt;isDot()) {
        $directorypath = $selectedDir.&quot;/&quot;.$fileinfo-&gt;getFilename();
        echo &quot;&lt;a href=&#39;?dir=&quot;.$directorypath.&quot;&#39;&gt;&quot;.$fileinfo-&gt;getFilename().&quot;&lt;/a&gt;&lt;br&gt;&quot;;
        
    }

huangapple
  • 本文由 发表于 2023年6月13日 18:31:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76463982.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定