Yükleniyor...

CSV dosya oluştur

CSV dosya oluştur
csv-dosya-olustur
    /**
     * CSV dosya olusturur
     * @param array $data
     * @param string $cikti_tipi
     * @param string $dosya_adi
     */
    function data2csv($data, $dosya_adi='/tmp/excel.csv'){
        # txt ye cevir
        $txt='';
        foreach ($data as $row) {
            foreach ($row as $value) {
                $txt .= $value . '; ';
            }
            $txt = trim($txt,'; ');
            $txt .="rn";
        }

        $txt = mb_convert_encoding($txt, 'ISO-8859-9', 'UTF-8');

        if (file_exists($dosya_adi)) {
            # bu dosya var , yeni dosya adı üret
            $bn = basename($dosya_adi);
            $yeni_dosya_adi = time() .'-'. $bn;
            $dosya_adi = str_replace($bn,$yeni_dosya_adi,$dosya_adi);
        }

        # dosyayi olustur
        touch($dosya_adi);
        @chmod($dosya_adi,0775);
        $fh = fopen($dosya_adi, 'w');
        fwrite($fh, $txt);
        fclose($fh);

        return $dosya_adi;
    }


  • SHARE

Tartışma




ya da
CAPTCHA Images