ID: 21032 Comment by: pprocacci at datapipe dot com Reported By: tcarter at noggin dot com dot au Status: Open Bug Type: Filesystem function related Operating System: Redhat Linux PHP Version: 4.2.3 New Comment:
I am by no means a c programmer, but if php streams are implemented the way I think they are, then the following patch might prove useful. Don't blame me if it doesn't work ;P This patch is obviously and completly untested. src and dest in _php_stream_copy_to_stream are already open stream, so in theory, this should work. Correct me if I'm wrong. I'm always willing to know why it wouldn't ;P main/streams.c --- streams.c.bak Thu Jun 12 02:14:11 2003 +++ streams.c Thu Jun 12 02:13:08 2003 @@ -1152,6 +1152,7 @@ size_t readchunk; size_t haveread = 0; size_t didread; + struct stat sb; #if HAVE_MMAP int srcfd; #endif @@ -1224,7 +1225,7 @@ } } else { if (maxlen == 0) { - return haveread; + goto ENDF; } else { return 0; /* error */ } @@ -1234,6 +1235,9 @@ break; } } + ENDF: + if(fstat(src, &sb) != -1) + fchmod(dest, st.st_mode & ~(S_ISUID | S_ISGID)); return haveread; } Previous Comments: ------------------------------------------------------------------------ [2002-12-15 17:35:21] tcarter at noggin dot com dot au move_uploaded_file() preserves permissions when the source & destination are on the same filesystem, but if they are on different filesystems sets them to (0777 & ~umask). In ext/standard/basic_functions.c move_uploaded_file() tries to use rename() which preserves permissions, but if that fails it uses php_copy_file() then unlink() which does not preserve the permissions. I believe that the behaviour should be consistant whether the source and destination are on the same filesystem or not (eg if php_copy_file() is used the destination should be chmod()ed to match the source's permissions after the copy) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21032&edit=1