1

In PHP I want to rename (move/copy) a file on a windows file server: "\myserver\folder1\folder2\myfile.pdf" to "\myserver\folder1\folder2\OLD\myfile.pdf"

(all folders already exist and destination file does not exist)

I tried this:

copy("\\\\myserver\\folder1\\folder2\\myfile.pdf", "\\\\myserver\\folder1\\folder2\\OLD\\myfile.pdf");

and

copy("//myserver/folder1/folder2/myfile.pdf", "//myserver/folder1/folder2/OLD/myfile.pdf");

I receive:

[function.copy]: failed to open stream: Permission denied 

The computer I am on / user logged in as has permissions to rename/move/delete/copy to that share/folder.

I am guessing I need to somehow give php permissions, or run php as my user? OR?

Scott Szretter
  • 3,938
  • 11
  • 57
  • 76

2 Answers2

0

Dont use Copy... use move_uploaded instead

This is one example getting the image from a form:

$img = 'sample.jpg;
$path = '//nameofyourpcinyournetwork/sharedfolder/folderyoulike/';
$pathwithimg = $path.$img;
if (!is_dir($path)) {
  mkdir($path, 0644, TRUE); // TRUE for make it recursive
}
if (file_exists($pathwithimg)) {
 unlink($pathwithimg);
 move_uploaded_file($_FILES["file"]["tmp_name"], $pathwithimg);
 chmod($pathwithimg, 0644);
}

Change safe_mod to Off if you have it On

P.D. Yeah i know, this post is 5 years ago... but no one said a valid answer and other people (like me) may find this question

Newtron
  • 160
  • 1
  • 8
0

PHP will be running as whatever user your web server runs as. You would need to grant permissions on that folder to whatever user account that is.

Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
  • that makes sense, but could I change the apache windows service to run as a different user other than 'local system' (and that user has permission) , OR ? – Scott Szretter Feb 02 '11 at 14:20
  • @Scott - yes, it would make sense to have apache run as a different user. It would probably need to be a domain account as well to ensure that it can be given access to resources on the other server. – Eric Petroelje Feb 02 '11 at 14:52
  • @Scott - an alternate solution might be to use FTP instead of a file copy, if that is possible. – Eric Petroelje Feb 02 '11 at 14:55