CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Custom file field upload not working from within drupal
Pages: [1]

Author Topic: Custom file field upload not working from within drupal  (Read 3949 times)

fralenuvol

  • Guest
Custom file field upload not working from within drupal
April 11, 2008, 02:57:50 am
Hello,
I installed civicrm 2.0 on drupal 5.7.
I created several custom fields for Civicrm Profiles which are correctly shown in drupal profile pages.

The only custom field which causes me issues is the custom file field.
If I try to upload a file from within drupal edit profile page I get the following error:
Code: [Select]
warning: rename(,/app2/hosting/htdocs/demo/joblook2/files/civicrm/custom/) [function.rename]: No such file or directory in /app2/hosting/htdocs/demo/joblook2/sites/all/modules/civicrm/CRM/Core/BAO/CustomField.php on line 952.
Notice at the beginning of the error in rename function, the empty value betwen parenthesis and comma.

I investigated in code of CustomField.php on line 952, and noticed that the variable $fName = $value['name'] is empty, when the file is uploaded from within Drupal. Only $value['type'] is correctly passed.

If I try to upload the file in the same custom file field from civicrm interface, everything works as expected, and it also shows up in drupal profile, for example as filename_7defb24b65fc89604b276aa5d24f6627.pdf.unknown (notice the "unknown" part at the end, is that normal?).

Only the upload from Drupal is not working.

Can somebody advice?



Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom file field upload not working from within drupal
April 11, 2008, 09:48:43 am
I just set up a test for this on our Drupal demo and it worked properly - so I suspect it's some configuration issue on your side (but not sure what :-( )... So you'll probably need to add some debug statements to the code to see why it might be failing in the Profile case.

You can see it working in a Profile by logging in to http://drupal.demo.civicrm.org/

To edit a profile for a contact where I've already uploaded an attachment:
http://drupal.demo.civicrm.org/civicrm/profile/edit?reset=1&id=92&gid=1

(my "file" type custom field is "Resume")
Protect your investment in CiviCRM by  becoming a Member!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom file field upload not working from within drupal
April 11, 2008, 12:06:38 pm

If you are trying to upload a file via the drupal 'My Account' page (wither register or edit) i suspect it will not work. In those forms, drupal controls the session and the buttons and we cannot add the code we need to make uploads work

as dave mentions, you can use the civicrm profiles to upload those files

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

fralenuvol

  • Guest
Re: Custom file field upload not working from within drupal
April 11, 2008, 02:47:20 pm
Thanks for your kind replies.

The scenario of the second reply is exactly the case.
I want authenticated users to have access to their edit/view profile only from drupal user account, while allowing only privileged roles to access civicrm interface (i.e. a Job site, candidates stay in the boundaries of drupal, and recruiters may search their profiles through civicrm).

The way it is implemented works perfectly, only the file field for a resume gives me this issue.
Therefore I tried also the "standalone" feature for civicrm profiles, and copied the html in a drupal page, in order to simulate a drupal profile section.

From there, the file field works too, but the form is not prepopulated with the current user's profile data, so it is not suitable.

If you have not other hints,
I think I will try to do it the other way:
Create a custom drupal content type as resume, associated to the drupal user account, and try to modify a custom contact screen template, in order to add the link to the resume for recruiter's needs.

Do you agree? :-)

« Last Edit: April 11, 2008, 02:51:07 pm by fralenuvol »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom file field upload not working from within drupal
April 11, 2008, 03:06:31 pm

if you expose the profile link to a logged in user, then that user's values are automatically loaded into the profile (similar to the edit page in my account). this is probably your best option

we dont link at all with drupal content types

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Custom file field upload not working from within drupal
April 11, 2008, 03:09:39 pm
Alternatively, you can give authenticated users a link to a CiviCRM profile in a Drupal block or menu item. It WILL pull in the existing data for the contact record which "belongs" to the logged in user if you use this format:

http://drupal.demo.civicrm.org/civicrm/profile/edit?reset=1&gid=1

Notice that I did not specify id=92 as in my earlier example. When no contact "id" is specified, the profile/edit path loads the profile form with data for the "current user". The gid parameter is the ID of the CiviCRM Profile - in these examples it's Profile 1 - Name and Address. You can see it's configuration here:

http://drupal.demo.civicrm.org/civicrm/admin/uf/group/field?reset=1&action=browse&gid=1

One more point - I think you'll need to use a complete URL (not a relative URL) if you're putting this link in a Drupal menu because otherwise the query-string portion get's mangled my Drupal. Some folks have used other web server config tricks to deal w/ this though - so search on this forum if that's a problem.
Protect your investment in CiviCRM by  becoming a Member!

fralenuvol

  • Guest
Re: Custom file field upload not working from within drupal
April 11, 2008, 03:33:00 pm
Thank you so much!
This is my first implementation of civicrm, therefore I had completely overseen the fact that civicrm profiles where seamlessly integrated in drupal.
I accessed civicrm contacts from search results, where the "contact interface" is different. Your options are suitable to my needs.

One last minor doubt:
I tested the file upload from both your demo and my site, and noticed that ".unknown" is appended to the file name in my demo.
Is this an issue? (Anyway it works correctly)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Custom file field upload not working from within drupal
April 11, 2008, 09:56:04 pm

if we dont recognize a valid extension type, we suffix the file with the unknown tag. This is primarily a security feature and avoid an uploaded file being run when invoked directly, if the person can guess the url and filename of the uploaded files

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

fralenuvol

  • Guest
Re: Custom file field upload not working from within drupal
April 11, 2008, 11:54:51 pm
Thanks again. I am able to proceed on my own now. 

By the way...
the answers of both of you were complementary for my understanding and your prompt replies made me feel a privileged forum user :-)

Francesco

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • Drupal Installations (Moderator: Piotr Szotkowski) »
  • Custom file field upload not working from within drupal

This forum was archived on 2017-11-26.