Skip to:
Content

BuddyPress.org

Opened 4 years ago

Last modified 3 years ago

#6708 reopened defect (bug)

Cannot upload group or member photos/avatars

Reported by: Plucker Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.3.3
Component: Groups Keywords:
Cc:

Description

I’m getting an odd error message:

Upload Failed! Error was: The uploaded file could not be moved to wp-content/uploads/group-avatars/4/group-avatars/4

Note the repeated “group-avatars/4” in the message.

The file is getting uploaded to “wp-content/uploads/group-avatars/4/” but doesn’t appear on the group.

I have tried uninstalling and re-installing BuddyPress and bbPress but am still stuck, any ideas please?

WP version: 4.3.1–en_GB
BuddyPress: Version 2.3.4
bbPress: Version 2.5.8
Theme: CustomizrVersion 3.4.13

Tried it with Twenty-Thirteen theme as well – same result.

Also tried removing all plug-ins and themes apart from twenty-thirteen theme, re-installing Wordpress and BuddyPress - issue is still there.

Can’t link to site as currently in development and not public but I can provide secure access if needed.

Change History (38)

#1 @Plucker
4 years ago

This happens in firefox and Safari on a Mac (El Capitain) and Firefox on Windows 7.

Server is running Linux and php version 5.6

Last edited 4 years ago by Plucker (previous) (diff)

#2 @DJPaul
4 years ago

Can you list all the active plugins, please? I'm pretty sure you must have something that's trying to manage file uploads for you.

#3 @Plucker
4 years ago

Only plugin that is active (or even installed) is BuddyPress.

#4 @DJPaul
4 years ago

The duplicated path bit is weird.

#5 @imath
4 years ago

  • Keywords reporter-feedback added

Hi @Plucker

i'm a bit surprised when you say:

The file is getting uploaded to “wp-content/uploads/group-avatars/4/” but doesn’t appear on the group.

  1. because the "odd" error message should only happen when the www user has no right to write files or folders inside wp-content/uploads.
  2. because if there's 2 images (thumb & full version) inside group-avatars/4 it should be dusplayed.
  3. if you have only one image inside it, it could possibly be a problem with your GD library eg: no support for png files. Have you tried with a jpg file ?

#6 @Plucker
4 years ago

I get exactly the same result with a jpg.

There is only one file created inside group-avatars/4 and it's the file I selected - no thumbnail version (I assume this would have a different file name?).

I also tried chmodding the entire uploads directory to 775 (it was 700) but that hasn't helped either.

Last edited 4 years ago by Plucker (previous) (diff)

#7 @Plucker
4 years ago

  • Keywords reporter-feedback removed

#8 @imath
4 years ago

Just to be sure: can you upload an image into the WordPress media library and then try to edit it using the cropping tool ?

It looks like the cropping step fails.

So maybe the support for libraries like GD or Imagick (used to edit images) is not active or missing on your config.

#9 @imath
4 years ago

  • Keywords reporter-feedback added

#10 @Plucker
4 years ago

I can upload a file to the wordpress media library and the Crop function works fine.

#11 @Plucker
4 years ago

  • Keywords reporter-feedback removed

#12 @imath
4 years ago

is it specific to groups or are users also not able to upload an avatar for their profile ?
Ah sorry for this silly question, it's in the title of your ticket. So it's not working at all.

btw, i've just rechecked on my side and i have no problem to upload a user or a group avatar. I'll try to see how your issue could happen.

Last edited 4 years ago by imath (previous) (diff)

#13 @imath
4 years ago

  • Keywords reporter-feedback added

@Plucker The only way to get:

Upload Failed! Error was: The uploaded file could not be moved to wp-content/uploads/group-avatars/4/group-avatars/4

is that the uploads base dir does not contain the WordPress Absolute Path. So a possible reason for this to happen is a plugin or a theme or a custom code in bp-custom.php or in a mu-plugin folder is playing with the WordPress uploads dir.

I've quickly built a testing tool, i understood your site were in development, so could you test it?

function issue_6708() {
	global $wp_filter;

	add_filter( 'bp_displayed_user_id', '__return_true' );
	add_filter( 'upload_dir', 'xprofile_avatar_upload_dir', 10, 0 );

	$uploads = wp_upload_dir();

	echo 'if there are other filters than xprofile_avatar_upload_dir, you should check these.<br/>';
	foreach( $wp_filter['upload_dir'] as $priority ) {
		var_dump( array_keys( $priority ) );
	}

	remove_filter( 'upload_dir', 'xprofile_avatar_upload_dir', 10, 0 );
	remove_filter( 'bp_displayed_user_id', '__return_true' );

	echo 'Following line should be true, the Absolute path must be in the upload basedir, and must start with it<br/>';
	var_dump( 0 === strpos( $uploads['basedir'], ABSPATH ) );

	echo '<br/>The uploads dir data is:<br/>';
	var_dump( $uploads );

	echo '<br/>Abspath is: ' . ABSPATH;
}
add_action( 'bp_actions', 'issue_6708' );

You should get something like this :

https://cldup.com/PXvriw9Cot.png

#14 @Plucker
4 years ago

  • Keywords reporter-feedback removed

OK, where should I put this and how do I run it please?

#15 @imath
4 years ago

Oh sorry, you use a bp-custom.php file as explained here: http://codex.buddypress.org/themes/bp-custom-php/

#16 @Plucker
4 years ago

OK, I got this

if there are other filters than xprofile_avatar_upload_dir, you should check these.
array(1) { [0]=> string(26) "xprofile_avatar_upload_dir" } Following line should be true, the Absolute path must be in the upload basedir, and must start with it
bool(true)
The uploads dir data is:
array(6) { path?=> string(87) "/ABSPATH/wp-content/uploads/avatars/1" url?=> string(71) "http://www.mentergwril.cymru/askdkasdasasd/wp-content/uploads/avatars/1" subdir?=> string(10) "/avatars/1" basedir?=> string(87) "/ABSPATH/wp-content/uploads/avatars/1" baseurl?=> string(71) "http://www.mentergwril.cymru/askdkasdasasd/wp-content/uploads/avatars/1" error?=> bool(false) }
Abspath is: /ABSPATH/

Last edited 4 years ago by imath (previous) (diff)

#17 @Plucker
4 years ago

I tried installing BuddyPress on another site on a different (Linux) server and, while I didn't have this exact problem I had a similar one. I could upload a file, it didn't throw that error message, it created a file and a thumbnail, it let me crop the image, but after clicking "finish" the avatar/photo did not appear on the group.

#18 @imath
4 years ago

Thank you for your reply, fyi I've truncated your paths in the comment # 16.

So the test is showing that you shouldn't have the problem, i'm lacking ideas...

Maybe:
remove the testing tool code from your bp-custom.php file and instead add this filter
add_filter( 'bp_avatar_is_front_edit', '__return_false' );

This will disable the avatar UI and you'll get a regular file upload button instead.

in your wp-config.php file turn WP_DEBUG to true and try uploading an avatar, if you have some errors output maybe it will help us understand.

#19 @Plucker
4 years ago

No errors either on screen or in the log file but the exact same error message - we're all scratching our heads now I think.

Last edited 4 years ago by Plucker (previous) (diff)

#20 @Plucker
4 years ago

Let's just let it pass for a while - if no-one else has a similar issue then it must be down to my ISP or server setup - it's not a particularly critical function and I can happily live without it for a few weeks.

#21 follow-up: @Plucker
4 years ago

I'm more and more convinced this is a bug - I have now completely destroyed the installation and re-installed it from scratch and still have this issue and see other issues with avatars being reported that are similar.

Now if I go to Members and "Change Profile Photo" and use the "Upload" function I get this error with the duplicate path.

However, If I use the "Take photo" option on my user then I can take a new photo and upload it successfully to the site and it works.

BUT the group avatar doesn't have the "Take Photo" option, only the "Upload" option, so I cannot get group photo added.


#22 in reply to: ↑ 21 @imath
4 years ago

Replying to Plucker:

I'm more and more convinced this is a bug - I have now completely destroyed the installation and re-installed it from scratch and still have this issue and see other issues with avatars being reported that are similar.

Well, it's working ok on my local dev & it's working ok on the test drive that is using BuddyPress 2.4-RC1: http://imath-buddypress.wpserveur.net/groups/ If you wish i can create an account for you to test on the test drive if you give me an email. The problem here is i can't reproduce your problem. And if it's working on both my local dev and the test drive, then my guess is there's something wrong with your config.

What are the other issues relative to avatar uploads ?

However, If I use the "Take photo" option on my user then I can take a new photo and upload it successfully to the site and it works.

There's no upload with the "Take Photo" picture, it's capturing the stream and creating a file with it.

#23 @Plucker
4 years ago

OK some days have gone by and I still have the issue - thinking it's permissions related but still concerned about the duplicated path components in the error message.

I've tried changing the permissions on the wp_content directory recursively to 777 and it didn't work, I also tried manually adding the duplicate directory at e.g. wp-content/uploads/group-avatars/4/group-avatars/4 but nothing seems to work.

I'm a bit stuck now, is there anything else I can check? group and owner of the directories and files are the same throughout the site - the only thing I can think of that may be an issue is that I cannot change permissions on files using ftp but have to use SSH. COuld this be a contributing factor?

Jeff

#24 @imath
4 years ago

I'm sorry, but i can't reproduce. Everything works fine for me on my local dev or on my test drive as i've explained earlier.

I don't think it's a permission issue, as directories are created and some files are uploaded/created using the 'take a photo' feature (if i understood well).

i agree that this > wp-content/uploads/group-avatars/4/group-avatars/4 is confusing. We'll take care of it in this ticket #6555.

It looks like when WordPress does this

$move_new_file = @ copy( $file['tmp_name'], $new_file );

in _wp_handle_upload, the result of the copy is false although your file has been uploaded (if i understood well again). A possible reason about why it's not happening for regular WordPress media is that WordPress uses 'move_uploaded_file' instead of 'copy'

You can try to know more about why the temporary file copy failed by using this kind of code into a bp-custom.php file:

add_filter( 'bp_avatar_is_front_edit', '__return_false' );

function dump_uploaded_file( $file ) {
	$uploads = wp_upload_dir();
	$filename = wp_unique_filename( $uploads['path'], $file['name'] );

	wp_die( sprintf( 'WordPress is trying to copy %s to %s', $file['tmp_name'], $uploads['path'] . '/' . $filename ) );
}
add_filter( 'bp_avatar_upload_prefilter', 'dump_uploaded_file', 10, 1 );

#25 follow-up: @Plucker
4 years ago

Again, thank you so much for your help, with that bp-custom code in place I get a message as follows:

WordPress is trying to copy /tmp/php72kSxH to .../wp-content/uploads/group-avatars/2/mg_board1.png

#26 in reply to: ↑ 25 @imath
4 years ago

Replying to Plucker:

WordPress is trying to copy /tmp/php72kSxH to .../wp-content/uploads/group-avatars/2/mg_board1.png

yw, i'd really like to understand what's going wrong with your config. About ^^, i guess you truncated the path to mg_bord1.png because here it should be an absolute path.

Last edited 4 years ago by imath (previous) (diff)

#27 @Plucker
4 years ago

I did because I didn't think it relevant, wordpress is installed in an htdocs directory which is the root of the website - do you need the absolute path?

#28 @imath
4 years ago

yes you're right. i was just confirming.

So copy could fail if the directory doesn't exist at the time you try to copy it. What is the result of this:

add_filter( 'bp_avatar_is_front_edit', '__return_false' );

function destination_dir_exists( $file ) {
	$uploads = wp_upload_dir();

	$dirs = array(
		$uploads['path'] => 0,
		dirname( $uploads['path'] ) => 0,
		dirname( dirname( $uploads['path'] ) ) => 0
	);

	foreach ( $dirs as $d => $v ) {
		$stat   = stat( $d );
		$rights = $stat['mode'] & 0007777;
		$dirs[ $d ] = '<br/>' . $d . ' : ' .$rights;
	}

	wp_die( sprintf( '%s is %san existing dir and rights are: %s', $uploads['path'], is_dir( $uploads['path'] ) ? '' : 'not', join( ',', $dirs ) ) );
}
add_filter( 'bp_avatar_upload_prefilter', 'destination_dir_exists', 10, 1 );

wp_upload_dir should create the different directories automatically if uploads belongs to www user and www user has correct rights on it.

Last edited 4 years ago by imath (previous) (diff)

#29 @Plucker
4 years ago

Hmm - odd -

Output is this:

/ABSPATH/wp-content/uploads/group-avatars/2 is an existing dir and rights are:
/ABSPATH/wp-content/uploads/group-avatars/2 : 511,
/ABSPATH/wp-content/uploads/group-avatars : 511,
/ABSPATH/uploads : 493

But when I look at all of those directories via SSH they are are as follows for all but the last one with the command:

ls -Rapl uploads

They are all 777

I guess I need to contact my ISP...

Last edited 4 years ago by imath (previous) (diff)

#30 @Plucker
4 years ago

The last one didn't exist so I created it and made it 777

#31 @imath
4 years ago

the last one /ABSPATH/uploads

should be /ABSPATH/wp-content/uploads

i think you made a mistake copying the path. I've rechecked my script an i'm getting on my local dev :

/ABSPATH/wp-content/uploads/avatars/1 is an existing dir and rights are:
/ABSPATH/wp-content/uploads/avatars/1 : 511,
/ABSPATH/wp-content/uploads/avatars : 511,
/ABSPATH/wp-content/uploads : 511

But 511 is actually 777. But i'm not sure having the uploads dir and subdirs at 777 is good idea. WordPress advises 755 in this page http://codex.wordpress.org/Changing_File_Permissions. I think an important thing is also the owner of the directory.

Last edited 4 years ago by imath (previous) (diff)

#32 @Plucker
4 years ago

I just copied and pasted what I got, but now (and after changing permissions back to 755) I get the same as you:

/ABSPATH/wp-content/uploads/group-avatars/1 is an existing dir and rights are:
/ABSPATH/wp-content/uploads/group-avatars/1 : 493,
/ABSPATH/wp-content/uploads/group-avatars : 493,
/ABSPATH/wp-content/uploads : 493

And thanks for pointing out that 777 Octal is 511 Decimal.

The owner and group are identical for every file and directory on the site but how do I check that this is the owner and group that Wordpress is using?

#33 @Plucker
4 years ago

So I contacted my ISP and they came back with this:

"Please be informed that changing permission is not allowed on our cluster hosting platforms and by default permission is set to 700 and cannot be changed. If your plugin on wordpress requires folder permission change to run, I am afraid this wouldn't work as stated above."

"By the way, have you checked the config to ensure that its trying to move the files to the correct server path?"

So I guess I'm stuck and my hosting company, whilst claiming to allow wordpress hosting, don't allow all buddy press feature to work.

Oh well, thanks for all the help anyway - guess it's something to do with that move vs. copy thing.

Jeff

#34 @DJPaul
4 years ago

@imath so was this a server configuration issue? Can we close?

#35 @imath
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

@DJPaul I think so. I'm going to close the ticket. @Plucker feel free to reopen it if you have new feedbacks about it.

#36 @Plucker
4 years ago

Yes it's fine - I've had a full refund from the hosting company as they are not fit for purpose when it comes to wordpress installations.

#37 @DarthTater
4 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I'm having same problem. BuddyPress Group settings are set to allow photo & cover image. I upload the image file, it seems fine but there is no button displayed to save the image or update the page.

However, when I log into my cpanel & check directory structure, there is a media subdirectory /group-avatars/7/ with the image uploaded 7 times now. But the group photo image won't display no matter what. File permissions are 0644, the parent directory /7 and the grandparent media directory permissions are 0755.

Is there a plugin or work around for this yet?

It seems odd that the parent directory name is the same as the number of images. Shouldn't the directory be a fixed name?

This ticket was mentioned in Slack in #buddypress by boone. View the logs.


3 years ago

Note: See TracTickets for help on using tickets.