0

my project directory is /public_html/test/

ownership and permission are as below,

drwxrwsr-x 8 lamp apache 4096 Apr  8 10:46 public_html
drwxrwsr-x 6 lamp apache 4096 Apr  2 14:58 test

a web application create directory, upload some files, move files from one directory to other directory under directory /public_html/test/files/

drwxrwsr-x 21 lamp apache 4096 Apr 24 13:58 files

now the problem is, I created directory called "mydirectory" using web application, it created under /public_html/test/files/ as below,

drwxrwsrwx 2 apache apache   4096 Apr 15 13:56 mydirectory

then I uploaded one file say "myfile.jpg", which by default get uploaded to /public_html/test/files/

-rwxrwxrwx 1 apache apache 595284 Apr 15 13:58 myfile.jpg

then my code use php function "move_uploaded_file" to move file to /public_html/test/files/ to /public_html/test/files/mydirectory/ as below

move_uploaded_file('/public_html/test/files/myfile.jpg', '/public_html/test/files/mydirectory/myfile.jpg');

It doesn't work. how to fix this?

if I change ownership of /public_html/test/files/mydirectory/ to lamp:apache instead apache:apache, and then upload the file again, move_uploaded_file works fine.

note: user "lamp" belongs to "apache" group.

===================

PHP Safe_mode was ON, just made it OFF and it worked :)

4

2 回答 2

1

这一行:

move_uploaded_file('/public_html/test/files/myfile.jpg', '/public_html/test/files/mydirectory/myfile.jpg');

应该是这样的:

move_uploaded_file('/public_html/test/files/myfile.jpg', '/public_html/test/files/mydirectory');
于 2013-05-03T13:25:12.757 回答
1

问题未经许可。您错误地使用了 move_uploaded_file() 函数。

正确用法是

move_uploaded_file ( string $filename , string $destination )

用这个替换你的代码。

move_uploaded_file('/public_html/test/files/myfile.jpg', '/public_html/test/files/mydirectory');

更多细节

http://php.net/manual/en/function.move-uploaded-file.php

于 2013-05-03T13:28:23.183 回答