When new users register without an avatar, the following message is displayed:

The selected file /usr/www/users/mysite/0 could not be copied, because no file by that name exists. Please check that you supplied the correct filename

Any support to help solve this error would be appreciated.

Comments

Omniweb’s picture

Try to change case 'insert' to this code:

case 'insert':
  // file repopulates from uploadcache
  $file = file_save_upload('picture_upload_register');
  if ($file) {
    $info = image_get_info($file->filepath);
    // save picture to correct path and update the row in the user table
   $destination = variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'.'. $info['extension'];
      if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
      db_query("UPDATE {users} SET picture='%s' WHERE uid=%d", $file->filepath, $user->uid);
    }
  }
break;
mmilano’s picture

thanks for the report and the code.

i should be able to update the module later this week. always appreciate the issue reports.

georgiebon’s picture

Thanks Xandle - I tried your code, but still get the same error message.

Omniweb’s picture

Yes, I've get the error too. Sorry.
It must be

if ($file) {

without negation.

I've correct my first post. Try it again, please.
It works without errors for user, but the validation error exist.

georgiebon’s picture

I tried the following code and no longer get an error message when a user registers with no picture:

case 'insert':
// file repopulates from uploadcache
$file = file_save_upload('picture_upload_register');
if ($file) {
	$info = image_get_info($file->filepath);
	// save picture to correct path and update the row in the user table
	$destination = variable_get('user_picture_path', 'pictures') .'/picture-'. $user->uid .'.'. $info['extension'];
	if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
		db_query("UPDATE {users} SET picture='%s' WHERE uid=%d", $file->filepath, $user->uid);
	}
}
if (!$file) {}
break;

Bear in mind that I am not really a coder, and this might not be the correct way to do this, but it seems to be working for me for now.

Omniweb’s picture

You should delete dummy line

if (!$file) {}

Use my code from the first post.

eMPee584’s picture

Title: Error Message Displayed When User Registers with No Avatar » Error Message Displayed When User Registers with No Avatar (f.e. automatically generated by listhandler)
Version: 6.x-1.0 » 6.x-1.x-dev
Component: Miscellaneous » Code
Category: support » bug
Status: Active » Needs review
StatusFileSize
new1.25 KB

just wanted to file this as bug report, here's my patch for this.

off’s picture

Patch work great!

I mean this code will be in the future version!

kbahey’s picture

Status: Needs review » Closed (duplicate)