Frage

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?

War es hilfreich?

Lösung

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.

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top