无法将文件移至已安装的网络共享文件夹

发布于 2025-01-30 17:09:59 字数 1213 浏览 1 评论 0原文

我正在尝试将文件上传到Office网络共享文件夹中,我对用户帐户的权限访问共享文件夹,我使用UNC路径来直接通过MOVE_UPLOAD_FILE函数上传文件,它不起作用,我遇到了此错误。

警告:move_uploaded_file(\\ 17.105.103.8 \ history \ tq_books \ tq_books \ 1.pdf):无法打开流:c:\ xampp \ xampp \ htdocs \ htdocs \ bookshelfs \ bookshelfs \ app \ app \ app \ app \ books.php in 14444444444444444444444444444444444444444444444444444444444 < /p>

之后144搜索 中的无效参数在我的PC上安装了该共享文件夹,我直接使用了安装的驱动器名称上传文件,然后我会遇到此错误

警告:move_uploaded_file(z:\ 30.pdf):无法打开流:c:\ xampp \ htdocs \ htdocs \ bookshelfs \ app \ app \ controllers \ books.php在第437行437

没有什么问题,如何解决此问题?我需要对Apache服务做一些配置吗?我正在尝试使用SMP协议,但是对我来说很难理解。

更新

$bookExt = pathinfo($_FILES['select_book']['name'], PATHINFO_EXTENSION);
$filename = ltrim($_POST['book_no'], '0') . '.' . $bookExt;
$tmpFilename = $_FILES['select_book']['tmp_name'];
$targetDir = '\\\\17.105.103.8\\History\\TQ_Books\\'; //before mount'
$targetDir = 'Z:'; //after mount
$fileTarget = $targetDir . $filename;

if (move_uploaded_file($tmpFilename, $fileTarget)) {
     die("success, uploaded");
} else {
     die("not uploaded");
}

I am trying to upload files into office network share folder, I have permission to my user account access the shared folder, I used UNC path to directly to upload files by move_upload_file function, It was not working I got this error.

Warning: move_uploaded_file(\\17.105.103.8\History\TQ_Books\1.PDF): failed to open stream: Invalid argument in C:\xampp\htdocs\bookshelfs\app\controllers\Books.php on line 144

after some search I mounted that shared folder on my pc, I directly used that mounted drive name to upload the file then I am getting this error

Warning: move_uploaded_file(Z:\30.PDF): failed to open stream: No such file or directory in C:\xampp\htdocs\bookshelfs\app\controllers\Books.php on line 437

I am not getting what's wrong with it, how to fix this issue? do I need to do some config with apache service? I was trying SMP protocol but It is very hard to understand for me.

UPDATE

$bookExt = pathinfo($_FILES['select_book']['name'], PATHINFO_EXTENSION);
$filename = ltrim($_POST['book_no'], '0') . '.' . $bookExt;
$tmpFilename = $_FILES['select_book']['tmp_name'];
$targetDir = '\\\\17.105.103.8\\History\\TQ_Books\\'; //before mount'
$targetDir = 'Z:'; //after mount
$fileTarget = $targetDir . $filename;

if (move_uploaded_file($tmpFilename, $fileTarget)) {
     die("success, uploaded");
} else {
     die("not uploaded");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

つ可否回来 2025-02-06 17:09:59

经过几天的研究,我得到了解决方案。 PHP无法直接与网络共享文件夹对话,在这种情况下,您必须将网络驱动器安装到系统。在安装驱动器之后,它将无法使用,因为问题是在这里由本地系统用户帐户登录的Apache服务器,因此您必须通过Apache Service将其更改为系统用户帐户。 (您可以在Windows服务上找到Apache Service)您必须通过管理员打开Windows Service,然后只能更改帐户。

然后,您可以在PHP文件上运行此代码进行安装。所有设置(重新启动PC后,您都可以看到安装的驱动器),

exec("net use Z: \\\\netowrk_ip\\folder /user:{sharefolder_domine}\{sharefolder_username} {sharefolder_password} /persistent:no 2>&1", $output, $return_var);

var_dump($output);

希望此答案对他人有所帮助。

After days of research, I got the solution. PHP cannot talk directly to the network share folder in this case you have to mount the network drive to your system. after if you mount the drive still it won't work, because the problem is here Apache server logged in by the local system user account, so you have to change it to your system user account through Apache service. (you can find apache service on windows services) you have to open windows service by admin then only you can change the account.

Then you can run this code on your PHP file to mount. all set (you can see your mounted drive after restart your pc)

exec("net use Z: \\\\netowrk_ip\\folder /user:{sharefolder_domine}\{sharefolder_username} {sharefolder_password} /persistent:no 2>&1", $output, $return_var);

var_dump($output);

I hope this answer helps others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文