Create upload dirs with same perms as wp-content. fixes #1784 #1726

git-svn-id: https://develop.svn.wordpress.org/trunk@2967 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2005-10-28 01:12:54 +00:00
parent 305c29d4e1
commit 471552766e
2 changed files with 8 additions and 4 deletions

View File

@ -1505,12 +1505,16 @@ function wp_upload_dir() {
$dir = 'wp-content/uploads'; $dir = 'wp-content/uploads';
$path = ABSPATH . $dir; $path = ABSPATH . $dir;
// Give the new dirs the same perms as wp-content.
$stat = stat(ABSPATH . 'wp-content');
$dir_perms = $stat['mode'] & 0000777; // Get the permission bits.
// Make sure we have an uploads dir // Make sure we have an uploads dir
if ( ! file_exists( $path ) ) { if ( ! file_exists( $path ) ) {
if ( ! mkdir( $path ) ) if ( ! mkdir( $path ) )
return array('error' => "Unable to create directory $path. Is its parent directory writable by the server?"); return array('error' => "Unable to create directory $path. Is its parent directory writable by the server?");
@ chmod( ABSPATH . $path, 0774 ); @ chmod( $path, $dir_perms );
} }
// Generate the yearly and monthly dirs // Generate the yearly and monthly dirs
@ -1524,14 +1528,14 @@ function wp_upload_dir() {
if ( ! file_exists( $pathy ) ) { if ( ! file_exists( $pathy ) ) {
if ( ! mkdir( $pathy ) ) if ( ! mkdir( $pathy ) )
return array('error' => "Unable to create directory $pathy. Is $path writable?"); return array('error' => "Unable to create directory $pathy. Is $path writable?");
@ chmod( $pathy, 0774 ); @ chmod( $pathy, $dir_perms );
} }
// Make sure we have a monthly dir // Make sure we have a monthly dir
if ( ! file_exists( $pathym ) ) { if ( ! file_exists( $pathym ) ) {
if ( ! mkdir( $pathym ) ) if ( ! mkdir( $pathym ) )
return array('error' => "Unable to create directory $pathym. Is $pathy writable?"); return array('error' => "Unable to create directory $pathym. Is $pathy writable?");
@ chmod( $pathym, 0774 ); @ chmod( $pathym, $dir_perms );
} }
$uploads = array('path' => $pathym, 'url' => get_option('siteurl') . "/$dir/$y/$m", 'error' => false); $uploads = array('path' => $pathym, 'url' => get_option('siteurl') . "/$dir/$y/$m", 'error' => false);

View File

@ -110,7 +110,7 @@ while ( file_exists($uploads['path'] . "/$filename") )
$file = $uploads['path'] . "/$filename"; $file = $uploads['path'] . "/$filename";
if ( false === move_uploaded_file($_FILES['image']['tmp_name'], $file) ) if ( false === move_uploaded_file($_FILES['image']['tmp_name'], $file) )
die('The uploaded file could not be moved to $file.'); die('The uploaded file could not be moved to $file.');
chmod($file, 0775); chmod($file, 0666); // FIXME: Need to set this according to rw bits on parent dir.
// Compute the URL // Compute the URL
$url = $uploads['url'] . "/$filename"; $url = $uploads['url'] . "/$filename";