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 »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Retrict the custom data field (file type)
Pages: [1]

Author Topic: Retrict the custom data field (file type)  (Read 1257 times)

friendly12345

  • Guest
Retrict the custom data field (file type)
September 10, 2010, 10:55:36 pm
Hi, I'm new to civiCRM, I hope somebody will help me on this.

I want to create a custom data field to allow user to upload the avatar for their profile.

I go to administer -> custom data to create field with type is file.

it work fine.

But some time the user will upload some file that is not an picture.

So how I can restrict them to only upload picture (image file type). and will be an error if they upload the wrong type.
And also if they upload is the image. So how can I modify the profile view layout. to make the avatar picture. lager.

Very appreciate for any help.

Thanks,
Yuan

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Retrict the custom data field (file type)
September 11, 2010, 11:32:01 am
Yuan - Rather than a custom field, you should probably use the built-in Contacts > Image URL field in our profile (you can re-label it when you add it to profile - so that it's named "Avatar" or whatever when you end-users see the profile form).

Go to CiviCRM > Administer > Configure > Global Settings > Safe File Extensions to remove (or add) extensions you want to accept. This list controls the types of files your users can upload.

Protect your investment in CiviCRM by  becoming a Member!

friendly12345

  • Guest
Re: Retrict the custom data field (file type)
September 12, 2010, 10:02:49 am
Thanks very much for your advice.
But How can I add the field into the profile. when I create a new field for a profile type I can't find the Image URL field.
Also When I create a new individual in the backend I have upload the image. But Can't see the image. and the image source is not an image. please view the attachment.

Thanks,
Yuan Chen

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Retrict the custom data field (file type)
September 14, 2010, 02:39:54 pm
I just tested this out on our 3.2.3 Joomla public demo and things seem to be working as fine / as expected. You should see the Image URL field when adding a Profile field - select Contacts in the first drop-down, then Image Url (screenshot attached).

The problem w/ path in Contact Edit form is possibly related to an invalid configuration, or a directory permissions problem on your server. Under CiviCRM > Administer > Global Settings check the Images directory under Directories and the Image Upload Path under Resource URLs. Make sure these are valid paths and that your webserver has read / write permissions there.
Protect your investment in CiviCRM by  becoming a Member!

friendly12345

  • Guest
Re: Retrict the custom data field (file type)
September 17, 2010, 07:58:45 am
Thanks Dave!

I have found the Image URL field to add in a profile.

But I still can't see the image after upload it.
I have check out the CiviCRM > Administer > Global Settings > directory and I'm sure that the image have been save ( I open the directory that save the image to make sure that the image have been save).

And as you can see in the previous post attachment file
when I view the contact the img tag is generated with src="http://localhost/Joomla15"
While I test on the demo server the img tag is generated with src="http://joomla.demo.civicrm.org/media/civicrm/custom/10878122_45836_7_f170058fde8e7a9562e0bd93769848a9.jpg"

Is it something I have config wrong that make it generate a wrong src? Or is it something wrong with my computer
I using WinXP SP3. xampp 1.7.0. PHP. 5.2.8

Thanks,
Yuan

« Last Edit: September 17, 2010, 08:03:19 am by friendly12345 »

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Retrict the custom data field (file type)
September 17, 2010, 10:37:01 am
Quite likely this is an issue related to running CiviCRM on a Windows machine. None of the core team use Windows as a web server (and it's not the "recommended" configuration). However, some folks have done it and you might get some help from this community contributed section of the documentation wiki:

http://wiki.civicrm.org/confluence/display/CRMDOC32/Installation+of+CiviCRM+on+Microsoft+IIS

Also searching on the CiviSearch page - http://civicrm.org/civisearch - on "civicrm on windows" pops up lots of other issues (and possibly solutions). If you figure it out - please post back here w/ the fix / solution.
Protect your investment in CiviCRM by  becoming a Member!

friendly12345

  • Guest
Re: Retrict the custom data field (file type)
September 18, 2010, 02:58:06 am
Thanks so much your help. My problem have been fixed.

I have debug the system and find out that in the file CRM/Contact/BAO/Contact.php line 753
Code: [Select]
$customFileUploadDirectory = strstr( $absolutePath , '/media' );
This code cause the problem. cause in window system the absolute path is "...\media" not "/media"
My solution is replace all the "\" with "/"
Code: [Select]
$customFileUploadDirectory = strstr( str_replace('\\', '/', $absolutePath), '/media' );
and then the upload image url will be work fine.

also I think this bug also occur at line 757 for drupal version and 760 for standalone version

Code: [Select]
$relativePath = $config->userFrameworkBaseURL . $absolutePathStr;
fix with

Code: [Select]
$relativePath = $config->userFrameworkBaseURL . str_replace('\\', '/', $absolutePathStr);
I also have create a issue at http://issues.civicrm.org/jira/browse/CRM-6834


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Retrict the custom data field (file type)

This forum was archived on 2017-11-26.