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.

AttachmentSize
reg_with_pic.module.patch738 bytes

#1

alex.ihlo - June 14, 2009 - 13:16

I've never done a patch before, where do you add this to?

#2

marcingy - June 17, 2009 - 17:54

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.

AttachmentSize
file_check.patch 1.2 KB

#3

alex.ihlo - June 18, 2009 - 19:06

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

VeryMisunderstood - June 21, 2009 - 04:01

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

-Shaman- - June 21, 2009 - 13:50

marcingy - Your patch isn't working, patch from first post is OK

#6

SamRose - July 4, 2009 - 01:59
Status:needs review» reviewed & tested by the community

Patch http://drupal.org/files/issues/file_check.patch in http://drupal.org/node/446094#comment-1713054 above working for me

#7

ktonini - July 23, 2009 - 21:56

2nd patch worked for me too. Thanks!

#8

Jaza - July 28, 2009 - 01:22

Also working for me. Let's get it committed, thanks!

#9

jacobangel - July 31, 2009 - 16:12

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

SamRose - July 31, 2009 - 18:36

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

SamRose - July 31, 2009 - 19:04
Status:reviewed & tested by the community» needs review

Turned http://drupal.org/node/446094#comment-1874748 into a patch and tested. No errors found.

AttachmentSize
regwithpic2.patch 1.57 KB

#12

Turkish Delight - August 7, 2009 - 16:55

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

shunshifu - October 20, 2009 - 02:33

Patch in #11 worked beautifully for me too

 
 

Drupal is a registered trademark of Dries Buytaert.