Ignore:
Timestamp:
03/18/11 18:18:12 (13 years ago)
Author:
alexandrecorreia
Message:

Ticket #1648 - Correcao( codigo ) e melhoria( laytou/informacao ) no upload de arquivos para o servidor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/filemanager/inc/upload.php

    r3610 r3879  
    1414 
    1515$bo = CreateObject('filemanager.bofilemanager'); 
    16  
    17 $c = CreateObject('phpgwapi.config','filemanager'); 
     16$c      = CreateObject('phpgwapi.config','filemanager'); 
    1817$c->read_repository(); 
    19 $current_config = $c->config_data; 
    20 $upload_max_size = $current_config['filemanager_Max_file_size']; 
    21 $path = $_POST['path']; 
    22 $notifUser = $_POST['notifTo']; 
    23 $show_upload_boxes = count($_FILES['upload_file']['name']); 
    24 $filesUpload = $_FILES['upload_file']; 
     18 
     19$current_config                 = $c->config_data; 
     20$upload_max_size                = $current_config['filemanager_Max_file_size']; 
     21$path                                   = $_POST['path']; 
     22$notifUser                              = $_POST['notifTo']; 
     23$show_upload_boxes      = count($_FILES['upload_file']['name']); 
     24$filesUpload                            = $_FILES['upload_file']; 
     25 
     26 
     27error_log( print_r($_FILES['upload_file'], true), 3, "/tmp/log" ); 
    2528 
    2629function create_summaryImage($file) 
     
    8487} 
    8588 
    86 if($path != '/') 
    87 { 
    88         for($i = 0; $i != $show_upload_boxes; $i++) 
    89         { 
    90                 if($badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True)) 
    91                 { 
    92                         $return[] = lang('Error:').lang('File names cannot contain "%1"', $badchar); 
     89if( $path != '/' ) 
     90{ 
     91        for( $i = 0; $i != $show_upload_boxes; $i++) 
     92        { 
     93                if ( $_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024) ) 
     94                { 
     95                        $return[] = array(  
     96                                                                "file"          => $_FILES['upload_file']['name'][$i] , 
     97                                                                "size"          => $_FILES['upload_file']['size'][$i] , 
     98                                                                "size_max"      => ($upload_max_size*1024*1024)  
     99                         ); 
    93100                        continue; 
    94101                } 
    95  
    96                 # Check to see if the file exists in the database, and get its info at the same time 
    97                 $ls_array = $bo->vfs->ls(array( 
    98                         'string'=> $path . '/' . $_FILES['upload_file']['name'][$i], 
    99                         'relatives'     => array(RELATIVE_NONE), 
    100                         'checksubdirs'  => False, 
    101                         'nofiles'       => True 
    102                 )); 
    103  
    104                 $fileinfo = $ls_array[0]; 
    105  
    106                 if($fileinfo['name']) 
    107                 { 
    108                         if($fileinfo['mime_type'] == 'Directory') 
    109                         { 
    110                                 $return[] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']); 
     102                elseif( $_FILES['upload_file']['size'][$i] > 0 ) 
     103                { 
     104                        if( $badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True )) 
     105                        { 
     106                                $return[] = array( 
     107                                                                "file"          => $_FILES['upload_file']['name'][$i], 
     108                                                                "badchar"       => lang('File names cannot contain "%1"', $badchar) 
     109                                );                                       
    111110                                continue; 
    112111                        } 
    113                 } 
    114  
    115                 if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024)) 
    116                 { 
    117                         $return[] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size); 
    118                         continue; 
    119                 } 
    120                 elseif($_FILES['upload_file']['size'][$i] > 0) 
    121                 { 
     112 
     113                        # Check to see if the file exists in the database, and get its info at the same time 
     114                        $ls_array = $bo->vfs->ls(array( 
     115                                                'string'=> $path . '/' . $_FILES['upload_file']['name'][$i], 
     116                                                'relatives'     => array(RELATIVE_NONE), 
     117                                                'checksubdirs'  => False, 
     118                                                'nofiles'       => True 
     119                        )); 
     120 
     121                        $fileinfo = $ls_array[0]; 
     122 
     123                        if( $fileinfo['name'] ) 
     124                        { 
     125                                if( $fileinfo['mime_type'] == 'Directory' ) 
     126                                { 
     127                                        $return[] = array( 
     128                                                                                "file"          => $_FILES['upload_file']['name'][$i], 
     129                                                                                "directory"     => lang('Cannot replace %1 because it is a directory', $fileinfo['name'] ) 
     130                                        ); 
     131                                        continue; 
     132                                } 
     133                        } 
     134 
    122135                        if($fileinfo['name'] && $fileinfo['deleteable'] != 'N') 
    123136                        { 
     
    131144                                $bo->vfs->cp($tmp_arr); 
    132145                                $tmp_arr=array( 
    133                                         'string'=> $_FILES['upload_file']['name'][$i], 
    134                                         'relatives'     => array(RELATIVE_ALL), 
    135                                         'attributes'    => array( 
    136                                                 'owner_id' => $bo->userinfo['username'], 
    137                                                 'modifiedby_id' => $bo->userinfo['username'], 
    138                                                 'size' => $_FILES['upload_file']['size'][$i], 
    139                                                 'mime_type' => $_FILES['upload_file']['type'][$i], 
    140                                                 'deleteable' => 'Y', 
    141                                                 'comment' => stripslashes($_POST['upload_comment'][$i]) 
     146                                                'string'=> $_FILES['upload_file']['name'][$i], 
     147                                                'relatives'     => array(RELATIVE_ALL), 
     148                                                'attributes'    => array( 
     149                                                        'owner_id' => $bo->userinfo['username'], 
     150                                                        'modifiedby_id' => $bo->userinfo['username'], 
     151                                                        'size' => $_FILES['upload_file']['size'][$i], 
     152                                                        'mime_type' => $_FILES['upload_file']['type'][$i], 
     153                                                        'deleteable' => 'Y', 
     154                                                        'comment' => stripslashes($_POST['upload_comment'][$i]) 
    142155                                        ) 
    143156                                ); 
    144157                                $bo->vfs->set_attributes($tmp_arr); 
    145158 
    146                                 $return[] = lang("There is a file %1, that was not replaced",$_FILES['upload_file']['name'][$i]); 
     159                                $return[] = array( 
     160                                                                "file"          => $_FILES['upload_file']['name'][$i],                                                                   
     161                                                                "undefined"     => lang( "There is a file %1, that was not replaced", $_FILES['upload_file']['name'][$i] ) 
     162                                ); 
    147163                        } 
    148164                        else 
     
    155171                                { 
    156172                                        $bo->vfs->set_attributes(array( 
    157                                                 'string'=> $_FILES['upload_file']['name'][$i], 
    158                                                 'relatives'     => array(RELATIVE_ALL), 
    159                                                 'attributes'=> array( 
    160                                                         'mime_type' => $_FILES['upload_file']['type'][$i], 
    161                                                         'comment' => stripslashes($_POST['upload_comment'][$i]) 
    162                                                 ) 
     173                                                        'string'                => $_FILES['upload_file']['name'][$i], 
     174                                                        'relatives'     => array(RELATIVE_ALL), 
     175                                                        'attributes'    => array( 
     176                                                                'mime_type'     => $_FILES['upload_file']['type'][$i], 
     177                                                                'comment'       => stripslashes($_POST['upload_comment'][$i]) 
     178                                                        ) 
    163179                                        )); 
    164180                                } 
    165                                 else{ 
    166                                         $return[] = lang('Error:').lang('It was not possible to send your file'); 
     181                                else 
     182                                { 
     183                                        $return[] = array (  
     184                                                                                "file"          => $_FILES['upload_file']['name'][$i], 
     185                                                                                "sendFile"      => lang('It was not possible to send your file') 
     186                                        ); 
    167187                                } 
    168  
    169                         } 
    170                 } 
    171                 elseif($_FILES['upload_file']['name'][$i]) 
     188                        } 
     189                } 
     190                elseif( $_FILES['upload_file']['name'][$i] ) 
    172191                { 
    173192                        $bo->vfs->touch(array( 
     
    177196 
    178197                        $bo->vfs->set_attributes(array( 
    179                                 'string'=> $_FILES['upload_file']['name'][$i], 
    180                                 'relatives'     => array(RELATIVE_ALL), 
    181                                 'attributes'=> array( 
    182                                         'mime_type' => $_FILES['upload_file']['type'][$i], 
    183                                         'comment' => stripslashes($_POST['upload_comment'][$i]) 
    184                                 ) 
     198                                        'string'                => $_FILES['upload_file']['name'][$i], 
     199                                        'relatives'     => array(RELATIVE_ALL), 
     200                                        'attributes'    => array( 
     201                                                                                'mime_type'     => $_FILES['upload_file']['type'][$i], 
     202                                                                                'comment'       => stripslashes($_POST['upload_comment'][$i]) 
     203                                        ) 
    185204                        )); 
    186  
    187                 } 
    188  
    189                 if (!(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE)) 
     205                } 
     206 
     207                if ( !(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE ) ) 
    190208                { 
    191209                        $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]); 
    192                         if ($content){ 
     210                        if ($content) 
     211                        { 
    193212                                $bo->vfs->set_summary(array( 
    194213                                        'string'=> $_FILES['upload_file']['name'][$i], 
Note: See TracChangeset for help on using the changeset viewer.