Error if no file uploaded during registration
shaisachs - April 27, 2009 - 12:38
| Project: | Register with Picture |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
If I use this module to register, but don't upload a picture during the registration process, I get this error:
The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.
This is because in the _user hook, the "insert" op doesn't check that file_save_upload returned successfully. The attached patch resolves this issue.
| Attachment | Size |
|---|---|
| reg_with_pic.module.patch | 738 bytes |

#1
I've never done a patch before, where do you add this to?
#2
Cleaner version of the patch that uses a check for $file rather than !$file. But yes checking for the presence of the file solves the file not found error. And alex.ihlo - http://drupal.org/patch/apply shows how to apply a patch.
#3
Yeah I found that before I replied to ur first post. But I just don't understand how to access the command line in the cPanel of my host, like that page says to do. ...I should've said that in my first reply-
Either way, thanks for the updated patch, definitely necessary.
#4
you do not access the command line in cPanel. You need shell access and not all hosts allow this. Your's may, if you prefer command line. however, you can set up something like cygwin (if using windows) on your localmachine and patch the files, then upload them.
#5
marcingy - Your patch isn't working, patch from first post is OK
#6
Patch http://drupal.org/files/issues/file_check.patch in http://drupal.org/node/446094#comment-1713054 above working for me
#7
2nd patch worked for me too. Thanks!
#8
Also working for me. Let's get it committed, thanks!
#9
wouldn't this be cleaner?
case 'insert':// file repopulates from uploadcache
if($file = file_save_upload('picture_upload_register')) {
$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;
#10
The patch at http://drupal.org/node/446094#comment-1713054 may be causing me problems. All user images on profile page disappear after a new user uploads, until cache is cleared.
#11
Turned http://drupal.org/node/446094#comment-1874748 into a patch and tested. No errors found.
#12
Firstly, I want to say that I've applied the patch in comment #11, and it works beautifully.
Random question for you all however. During my tests, I created a user and ran into the error message when no picture was uploaded. However, I decided that some users may decide to go and recreate their account, in which case I receive a "the picture was resized" message. When I check my avatar file I find that no picture was uploaded (as I imagine no user could be associated with that picture due to the fact that a user was created previously), however I'm curious, is that resized picture floating around in cache somewhere? Thanks!
#13
Patch in #11 worked beautifully for me too