Download & Extend

Error Message Displayed When User Registers with No Avatar (f.e. automatically generated by listhandler)

Project:Register with Picture
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

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

#1

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;

#2

thanks for the report and the code.

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

#3

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

#4

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.

#5

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.

#6

You should delete dummy line

if (!$file) {}

Use my code from the first post.

#7

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 request» bug report
Status:active» needs review

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

AttachmentSize
reg_with_pic-fix-error-if-upload-failed.patch 1.25 KB

#8

Patch work great!

I mean this code will be in the future version!

#9

Status:needs review» closed (duplicate)

Marking this as a duplicate of #446094: Error if no file uploaded during registration

nobody click here