简体   繁体   English

在php中将文件上传到网络驱动器

[英]upload file to network drive in php

php script for uploading file to mapped network drive is not working . 用于将文件上传到映射的网络驱动器的php脚本不起作用。 Following are the php script: 以下是php脚本:

$newfilename = "something.wav";
$path  = 'Y:\\uploaded\\'.$newfilename;
copy($_FILES['ufile']['tmp_name'], $path);

I have also check permission for network drive folder.I have Y drive mapped to the network drive(10.4.4.32) d drive within uploaded folder. 我还检查了网络驱动器文件夹的权限。我已将Y驱动器映射到上载文件夹中的网络驱动器(10.4.4.32)d驱动器。 It have full control permission. 它具有完全控制权限。 I have tried following path for network drive: 我尝试过以下网络驱动器的路径:

  • Y:\\uploaded\\ Y:\\上载\\
  • \\\\10.4.4.32\\d$\\uploaded\\ \\\\ 10.4.4.32 \\ d $ \\已上传\\
  • move_uploaded_file($_FILES['ufile']['tmp_name'], $path); move_uploaded_file($ _ FILES ['ufile'] ['tmp_name'],$ path);

But, It works on local drive like: 但是,它可以在本地驱动器上运行,例如:

  • d:\\uploaded\\ The file is uploaded in local drive but could not uploaded in network drive. d:\\ uploaded \\该文件已上传到本地驱动器,但无法上传到网络驱动器。 I have used php 5.3 and IIS 7 for application 我已将php 5.3和IIS 7用于应用程序

Errors Showed: Warning: copy(\\10.4.4.32\\d$\\uploaded\\test.wav): failed to open stream: Permission denied in C:\\inetpub\\wwwroot\\myapp\\upload.php on line 107 显示的错误: 警告:copy(\\ 10.4.4.32 \\ d $ \\ uploaded \\ test.wav):无法打开流:权限在第107行的C:\\ inetpub \\ wwwroot \\ myapp \\ upload.php中被拒绝

I have allow permission of full control in the properties of the uploaded folder for EVERYONE user. 我对所有人的上传文件夹的属性均拥有完全控制的权限。 Is there any other permission , I should fixed. 还有其他许可,我应该解决。

First, check if copy() returns false. 首先,检查copy()返回false。 This indicates that there is really an error. 这表明确实存在错误。

Then, enable the track_errors directive in your php.ini, as well as display_errors and error_reporting to the highest level. 然后,在php.ini中启用track_errors指令,以及将display_errorserror_reporting设置为最高级别。 When track_errors is activated (and you restarted your webserver), use the following line after the copy: 激活track_errors (并重新启动Web服务器)后,在复制后使用以下行:

var_dump($php_errormsg, error_get_last());

This should give you a better hint about the problem. 这应该为您提供有关该问题的更好提示。


Also make sure that if you're using safe_mode and open_basedir , the path you're moving to is allowed. 还要确保,如果您使用safe_modeopen_basedir ,则允许您移动到的路径。

network drive may not work for neither apache nor php , so use this $path = "\\\\machine-name\\share_path\\"; 网络驱动器可能不适用于apache和php,因此请使用此$ path =“ \\\\ machine-name \\ share_path \\”;

set up an user account on BOTH computer such as user : ApacheUser 在两台计算机上都设置一个用户帐户,例如user:ApacheUser

go to services and click Apache , and use the account just created to logon (second tab) the Apache service of source computer 转到服务并单击Apache,然后使用刚创建的帐户登录(第二个选项卡)源计算机的Apache服务。

restart the apache service 重新启动apache服务

then it should work now 那么现在应该可以工作了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM