菜单

typo3文件操作类

2010年04月8日 - typo3

 $file1 = t3lib_div::tempnam(‘file’);
                t3lib_div::writeFile($file1,$sFileContent);
                t3lib_div::upload_copy_move($file1,’../../../../fileadmin/export_user/feusers.’.$export_type);
                unlink($file1);

附xls,csv,export方法:
   /**
     * write the file for export
     *
     * @return    file data
     */
    function writeFile()
    {
        global $LANG;

        $sSelectCol = array();
        $sSelectUsg = array();
        $sFirstLine = array();
        $sFileContent = ”;

        foreach ($this->getColumns() as $sCol){
            if (t3lib_div::GPvar(‘col_’.$sCol)){
                array_push($sSelectCol, $sCol);
                array_push($sFirstLine, ‘col_’.$sCol);
            }
        }

        foreach ($this->getUsergroups() as $sUsg){
            if (t3lib_div::GPvar(‘usg_’.$sUsg[‘uid’])){
                array_push($sSelectUsg, $sUsg[‘uid’]);
            }
        }

        if (count($sSelectCol) > 0 && count($sSelectUsg)>0 && t3lib_div::GPvar(‘export_type’) != ”){

            $aResult = $this->getSqlQueryData(implode(‘,’, $sSelectCol), ‘fe_users’, ‘usergroup=’.implode(‘,’, $sSelectUsg));

            if (!empty($aResult)){

                if (t3lib_div::GPvar(‘export_type’) == ‘csv’){
                    foreach ($sFirstLine as $sF){
                        $colname = ($LANG->getLL($sF)) ? $LANG->getLL($sF) : ‘[‘.$sF.’]’;
                        $sFileContent .= ‘"’.$colname.’";’;
                    }
                    $sFileContent .= "\n";
                    foreach ($aResult as $aR) $sFileContent .= ‘"’.implode(‘";"’, array_values($aR)).’";’."\n";
                    $export_type = ‘csv’;
                } elseif (t3lib_div::GPvar(‘export_type’) == ‘xls’){
                    $sFileContent .=
                        ‘<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
                            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                            <html>
                                <head>
                                    <meta http-equiv="Content-type" content="text/html;charset=utf-8" />
                                    <style id="Classeur1_16681_Styles">
                                    </style>
                                </head>
                                <body>
                                    <div id="Classeur1_16681" align=center x:publishsource="Excel">
                                        <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse"><tr>’;

                    foreach ($sFirstLine as $sF){
                        $colname = ($LANG->getLL($sF)) ? $LANG->getLL($sF) : ‘[‘.$sF.’]’;
                        $sFileContent .= ‘<td class=xl2216681 nowrap>’.$colname.'</td>’;
                    }
                    $sFileContent .= ‘</tr>’;
                    foreach ($aResult as $aR) $sFileContent .= ‘<tr><td class=xl2216681 nowrap>’.implode(‘</td><td class=xl2216681 nowrap>’, array_values($aR)).'</td></tr>’;
                    $sFileContent .= ‘</table></div></body></html>’;
                    $export_type = ‘xls’;
                }

                $file1 = t3lib_div::tempnam(‘file’);
                t3lib_div::writeFile($file1,$sFileContent);
                t3lib_div::upload_copy_move($file1,’../../../../fileadmin/export_user/feusers.’.$export_type);
                unlink($file1);

                $output =
                    ‘<table cellpadding="0" cellspcing="0">
                        <tr>
                            <td style="padding-right: 5px;"><img src="moduleicon.gif" alt="Download" /></td>
                            <td style="font-size: 14px; font-weight: bold;">’.$LANG->getLL(‘download_file’).’:</td>
                            <td style="padding-left: 10px;" colspan="2"><a style="text-decoration: underline; font-size: 14px; font-weight: bold;" href="../../../../fileadmin/export_user/feusers.’.$export_type.’" >feusers.’.$export_type.'</a></td>
                        </tr>
                    </table>’;

                return $output;

            } else return ‘<span style="color: red; font-weight: bold; font-size: 14px;">’.$LANG->getLL(‘error’).’: ‘.$LANG->getLL(‘error_nofeuser’).'</span>’;

        } else return ‘<span style="color: red; font-weight: bold; font-size: 14px;">’.$LANG->getLL(‘error’).’: ‘.$LANG->getLL(‘error_nodata’).'</span>’;

    }
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注