如何访问远程目录并用PHP复制文件 [英] How to access a remote directory and copy files in PHP

查看:161
本文介绍了如何访问远程目录并用PHP复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从远程目录复制文件。但是我不知道如何写UNC。我可以使用file:// Server / Production / Images在浏览器中打开目录,但是如果我只是在我的PHP脚本中使用这个路径,它就无法工作。

  $ origin =file:// Sever / Prodution / Images; 
$ file = scandir($ origin);

结果是:警告:scandir():不支持远程主机文件访问b
$ b

我已经以管理员身份运行了我的wampsever,因此我认为它可以访问远程服务器。

解决方案 http:// localhost / path / to / file 或 http://127.0.0.1/path/to/file 。您还需要确保文件在您的计算机上具有网络可访问目录。例如,如果你的wamp栈的webroot是C:\programs\wamp\apache\html\,而你试图访问的文件位于C:\Sever\Prodution\Images那么文件将无法访问。让感觉?


I want to copy files from a remote directory. But I don't know how to write its UNC. I can use file://Server/Production/Images to open the directory in a browser, but it can't work if I just use this path in my PHP script.

$origin = "file://Sever/Prodution/Images";
$file = scandir($origin);

The rusult is : Warning: scandir(): remote host file access not supported

I have run my wampsever as an administrator, so I assume it can access to remote sever.

解决方案

Without doing any research, I am not sure that 'file://' is a proper protocol to use in a server environment. If you are testing remote file access but are wanting to access files on the local server, you could use http://localhost/path/to/file or http://127.0.0.1/path/to/file. You will also need to make sure that the file is with a 'web accessible' directory on your machine. For example, if your wamp stack's webroot is C:\programs\wamp\apache\html\ and the file you are trying to access is located in C:\Sever\Prodution\Images then the file will not be accessible. Make Sense?

这篇关于如何访问远程目录并用PHP复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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