Results 1 to 5 of 5

Thread: Multiple Document Uploads

  1. #1
    kevinroy is offline Junior Member
    Join Date
    Sep 2009
    Posts
    2

    Default Multiple Document Uploads

    Hi All,

    I am wondering if it is at all possible to upload multiple files under the create document tab, I want to for example upload a whole set of documents under a single description e.g. FAQ or SALES etc, at the moment and as by default it is a single file at a time which for the 2000 documents I need to upload is going to take me a while.

    I am running the latest 5.2 community edition and I am not sure if this is possible or not, or if there is a plug in or some such other method of doing what I need to do ?

    Kind Regards

    Kevin.

  2. #2
    salesagility's Avatar
    salesagility is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    2,379

    Default Re: Multiple Document Uploads

    Yes

    you can upload all the documents into the cache/uploads directory. you would have to give each document a unique name that fits with the documents_id key (something like c8e6b120-68b0-9f1f-b092-447593a114343) and then write a script that inserted the document ids and descriptions into the documents table.

    This may take you longer than manually uploading the documents.

  3. #3
    kevinroy is offline Junior Member
    Join Date
    Sep 2009
    Posts
    2

    Default Re: Multiple Document Uploads

    Hmm, this seems like an oversight, you are allowed to upload docs but only one at a time, as a newbie to sugar is this one of those things that everyone requests is put in, or do you know of any third party plugins that will allow me to do this as I am not a coder.

    Kind Regards
    Kevin.

  4. #4
    salesagility's Avatar
    salesagility is offline Sugar Community Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    2,379

    Default Re: Multiple Document Uploads

    Sorry, I'm not aware of any extensions ....

  5. #5
    Danielg42 is offline Sugar Community Member
    Join Date
    Jun 2006
    Location
    Orange County, CA
    Posts
    187

    Default Re: Multiple Document Uploads

    I had to upload a bajillion documents myself, so here's what I wrote up.
    No promises or anything, but it works for me.

    If anything you can make it better or whatever.
    PHP Code:
    <?php
    #Creates the entries for a folder full of documents in the sugar database
    #Copy over the contents of the folder defined by $moved, to /cache/upload when you're done
    #Variables start at line 6, line 23, then again at line 28

    $host="localhost";  # MySQL data here
    $user="root";
    $password="SECRETPASSWORD!";
    $database="sugar";

    #Don't touch!
    echo "logging in";
    $con mysql_connect("$host","$user","$password");
    if (!
    $con)
    {
      die(
    'Could not connect: ' mysql_error());
        echo 
    "failed to connect";
    }

    mysql_select_db("$database"$con);

    #Put the folder of documents here... don't use ./ or weird stuff happens
    ListFolder("./CGI");


    function 
    ListFolder($path)
    {
    $userID='da3308a4-9be7-ee40-7116-44ce699546c3'#UID of the user you want to be uploading the documents
    $category="Knowledge Base"#Document Category
    $subCategory="Documentation"#Subcategory
    $moved="c:/server/apache2/htdocs/TEST"#the folder you want your files copyed over to. 
                                    #Copy the contents of this folder to /cache/upload when you're done
                                    
    #No more variables below this line
    #Leave dates alone unless you ... whatever
    $date=date("Y-m-d H:i:s");
    $roughDate=date("Y-m-d");

        
    #using the opendir function
        
    $dir_handle = @opendir($path) or die("Unable to open $path");
        
    #display the target folder.
        
    while (false !== ($file readdir($dir_handle)))
        {
            if(
    $file!="." && $file!="..")
            {
                if (
    is_dir($path."/".$file))
                {
                    
    #Display a list of sub folders.
                    
    ListFolder($path."/".$file);
                }
                else
                {
                    
    #Sets up the file to be uploaded then moved
                    
    $pathfile="$path/$file";
                    
    $ext explode(".",$file);
                    
    $ext $ext[1];
                    
    $guid=guid();
                    
    $DOC=guid();
                    
    $test="$moved/$guid";
                    echo 
    "$file </br>";
                    echo 
    "$moved </br> $guid </br> $test </br>";
                    
    #SQL commands created
                    
    $sql="INSERT INTO `$database`.`documents` (`id`, `document_name`, `active_date`, `exp_date`, `description`, `category_id`, `subcategory_id`, `status_id`, `date_entered`, `date_modified`, `deleted`, `modified_user_id`, `created_by`, `document_revision_id`, `related_doc_id`, `related_doc_rev_id`, `is_template`, `template_type`) 
                    VALUES ('$DOC', '$file', '$roughDate', '$roughDate', NULL, '$category', '$subCategory', 'Live', '$date', '$date', '0', '$userID', '$userID', '$guid', '', '', '0', NULL);"
    ;
                    
    mysql_query($sql);
                    echo 
    $sql;
                    
    $sql="INSERT INTO `$database`.`document_revisions` (`id`, `change_log`, `document_id`, `date_entered`, `created_by`, `filename`, `file_ext`, `file_mime_type`, `revision`, `deleted`, `date_modified`) 
                    VALUES ('$guid', 'first entry', '$DOC', '$date', '$userID', '$file', '$ext', 'documentation', '1', '0', '$date');"
    ;
                    
    #SQL commands executed
                    
    mysql_query($sql);
                    echo 
    "$sql </br>";
                    
    #Give the file a UID as its name, so it can be copied to /cache/upload
                    
    copy("$pathfile","$test");
                }
            }
        }
       
        
    #closing the directory
        
    closedir($dir_handle);
    }

    #weeee! Stolen sugar functions!
    function guid (){
         
    $microTime microtime();
        list(
    $a_dec$a_sec) = explode(" "$microTime);

        
    $dec_hex sprintf("%x"$a_dec1000000);
        
    $sec_hex sprintf("%x"$a_sec);

        
    ensure_length($dec_hex5);
        
    ensure_length($sec_hex6);

        
    $guid "";
        
    $guid .= $dec_hex;
        
    $guid .= create_guid_section(3);
        
    $guid .= '-';
        
    $guid .= create_guid_section(4);
        
    $guid .= '-';
        
    $guid .= create_guid_section(4);
        
    $guid .= '-';
        
    $guid .= create_guid_section(4);
        
    $guid .= '-';
        
    $guid .= $sec_hex;
        
    $guid .= create_guid_section(6);
        return 
    $guid;
    }
    function 
    create_guid_section($characters)
    {
        
    $return "";
        for(
    $i=0$i<$characters$i++)
        {
            
    $return .= sprintf("%x"mt_rand(0,15));
        }
        return 
    $return;
    }

    function 
    ensure_length(&$string$length)
    {
        
    $strlen strlen($string);
        if(
    $strlen $length)
        {
            
    $string str_pad($string,$length,"0");
        }
        else if(
    $strlen $length)
        {
            
    $string substr($string0$length);
        }
    }

    function 
    microtime_diff($a$b) {
       list(
    $a_dec$a_sec) = explode(" "$a);
       list(
    $b_dec$b_sec) = explode(" "$b);
       return 
    $b_sec $a_sec $b_dec $a_dec;
    }

    ?>
    Last edited by Danielg42; 2009-09-04 at 04:08 PM. Reason: stuff

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 2009-04-29, 04:42 PM
  2. Massive uploads of documents
    By danmaz74 in forum Developer Help
    Replies: 1
    Last Post: 2009-02-10, 09:53 AM
  3. File Uploads in custom modules
    By spyro187 in forum Developer Help
    Replies: 0
    Last Post: 2008-07-02, 01:21 PM
  4. Large file uploads
    By lmcanada in forum Help
    Replies: 0
    Last Post: 2008-02-19, 05:28 PM
  5. Document bulk uploads
    By rlbyrd in forum Feature Requests
    Replies: 0
    Last Post: 2006-09-04, 10:28 PM

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
  •