PHP 在单独的驱动器上上传/读取文件 [英] PHP upload/read files on separate drive

查看:27
本文介绍了PHP 在单独的驱动器上上传/读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在单独的驱动器上上传/查看文件.

I need to be able to upload/view files on a separate drive.

现在,我的站点位于 C: 驱动器上的 htdocs 文件夹中.我们已经在 D: 驱动器上分配了空间来上传和查看文件.

Right now, my site is in the htdocs folder on the C: drive. We have been allocated space on the D: drive to upload and view files.

使用下面的代码,我可以使用 scandir 查看 htdocs 文件夹中的内容:

Using the code below, I can use scandir to view what is located in htdocs folder:

<?php
 $dir    = '../../htdocs/';
 $files1 = scandir($dir);
 $files2 = scandir($dir, 1);

 print_r($files1);
 print_r($files2);
?>

但是我需要再往回走一些才能到达 D: 驱动器.我不确定这是否可能.

But I need to traverse back a few more to be able to get to the D: drive. I am not sure if this is even possible.

使用上面的代码,当我尝试遍历 D: 驱动器时,路径看起来像这样:

Using the above code, when I attempt to traverse to the D: drive, the path would look something like this:

$dir    = '../../../D:/uploadFiles/';

当返回并查看 D: 驱动器中的内容时,我不确定这是否是正确的格式.我想如果是这样,我会在屏幕上看到一些东西,而我不是.

I am not sure if that is the correct format when going back and viewing something in the D: drive. I guess if it was, I would be seeing something on the screen, which I am not.

在网上进行研究后,我能找到的最接近的是这篇文章:

Upon conducting my research online, the closest thing that I could find was this post:

上传文件到驱动器 d://php

但我需要能够先读取 D: 驱动器上文件夹中的文件.

But I need to be able to first read the files in the folder on the D: drive.

我正在尝试使用 PHP 做的事情可行吗?如果是,我该如何修复我的路径,以便我可以看到 D: 驱动器上的 uploadFiles 文件夹中的文件?

Is what I am trying to do possible using PHP? If it is, how can I fix my path so that I can see the files in the uploadFiles folder on the D: drive?

推荐答案

所有 目录函数.

简单:

scandir('C:/some/path/uploadFiles');
scandir('D:/some/path/www/htdocs');

或者别的什么……写出完整路径.甚至不要做那些 ../../ 的事情.相对路径/绝对路径.我认为你把事情复杂化了.

Or whatever... Write out the full paths. Don't even do that ../../ stuff. Relative paths / absolute paths. I think you are overcomplicating things.

这篇关于PHP 在单独的驱动器上上传/读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆