Results 1 to 1 of 1

Thread: Upload Image/Photo to a Contact/Opportunity or any other record - How to

  1. #1
    mrbarletta is offline Junior Member
    Join Date
    Jun 2009
    Posts
    6

    Lightbulb Upload Image/Photo to a Contact/Opportunity or any other record - How to

    Hi there,

    Do you need an Image / Photo Field for any module custom or not? I did, and I knocked my head multiple times wondering why the Image Field in the studio did not work! (its in the studio but it has no logic to support it in the detail/editviews) any way...

    Happy ending though! .. Here is how I did it - if a real developer stumble upon this: shoot any comment/improvement!

    1) Create a new Field of type Image for your desired module
    2) Add it to your Detail View / Edit View etc
    3) Go to the folder include/SugarFields/Fields/ and download+decompress the 4 files in the zip I posted
    4) Try it. There should be a browse link in the EDITVIEW where the field is displayed, and it should display the image in DETAILVIEW.

    It works :P - but there are some tricks....
    1) EDITVIEW - Remove button needs a change in the controller of the module where you added the field. If you added an image field for the contact module, then you need to change the Contact module controller and add something like this:
    PHP Code:
     function action_editview(){

                    
    $this->view 'edit';
                    
    $GLOBALS['view'] = $this->view;
                    if(!empty(
    $_REQUEST['deleteAttachment'])){
                            
    ob_clean();
                            
                            
    $removeFile clean_path(getAbsolutePath("{$GLOBALS['sugar_config']['upload_dir']}{$this->id}"));
      
    //We should remove the file - i don't do it --  add the logic to delete it below.
                            
    echo 'true';
                            
    sugar_cleanup(true);
                    }

            } 
    Be careful, this code does not actually Deleted the file (i did not needed it) add it your self :P

    2) You can ONLY add 1 of this FIELD TYPE , current implementation is to NAME THE FILE with the ID of the BEAN. It means that if the contact id is XYZ the file fill be under cache/upload/XYZ . So if you add more than 1 Image Field, both will point to the same pic and be overwriten it sucks but, I am happy with this 0.1 pre alpha version


    Final notes:

    • This image field is an imitation of the File Field from which I based this.
    • I use this for the great Advance Open Sales AOS Product Module and it works like a charm
    • Tested in 6.3.1 CE with AJAX interface
    • It does not upload the file through AJAX, is during the POST - The logic for saving the file is inside the SugarImageField.php


    pura vida ~ mrbarletta
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [TUTORIAL] How to Add a Photo to a Contact Record
    By chad.hutchins in forum Developer Help
    Replies: 2
    Last Post: 2010-01-12, 04:18 PM
  2. Can't upload image to server any more?
    By rleroux in forum Help
    Replies: 2
    Last Post: 2009-01-15, 06:08 AM
  3. Incruster une photo dans le module contact
    By jarr in forum Français
    Replies: 4
    Last Post: 2007-04-02, 09:02 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •