当前位置: 首页>>代码示例>>PHP>>正文


PHP FileUtil::isCSVFile方法代码示例

本文整理汇总了PHP中FileUtil::isCSVFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::isCSVFile方法的具体用法?PHP FileUtil::isCSVFile怎么用?PHP FileUtil::isCSVFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileUtil的用法示例。


在下文中一共展示了FileUtil::isCSVFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createTemplate

function createTemplate($sid, $dataSource_dir, $dataSource_dirPath, $excelFileMode, $ext)
{
    if ($ext == 'csv') {
        $template = 'csv-to-database.ktr';
    } else {
        $template = 'excel-to-database.ktr';
    }
    //'excel-to-target_schema.ktr';
    $newDir = "temp/{$sid}";
    if (!file_exists(mnmpath . $newDir)) {
        mkdir(mnmpath . $newDir);
    }
    if ($excelFileMode == 'append') {
        $ktrFilePath = mnmpath . "{$newDir}/{$sid}.ktr";
        $ktrFileURL = my_base_url . my_pligg_base . "/{$newDir}/{$sid}.ktr";
        if (!file_exists($ktrFilePath)) {
            copy($template, $ktrFilePath);
        }
        foreach (scandir($dataSource_dirPath) as $dataSource_filename) {
            if (FileUtil::isXLSXFile($dataSource_filename) || FileUtil::isXLSFile($dataSource_filename)) {
                $filenames[] = $dataSource_filename;
                $filePaths[] = $dataSource_dirPath . $dataSource_filename;
                $fileURLs[] = my_base_url . my_pligg_base . "/{$dataSource_dir}" . $dataSource_filename;
            }
        }
        $ktrManagers[$filenames[0]] = new KTRManager($template, $ktrFilePath, $filePaths, $sid, $fileURLs, $ktrFileURL, $ext);
    } else {
        foreach (scandir($dataSource_dirPath) as $dataSource_filename) {
            if (FileUtil::isXLSXFile($dataSource_filename) || FileUtil::isXLSFile($dataSource_filename) || FileUtil::isCSVFile($dataSource_filename)) {
                $filenames[] = $dataSource_filename;
                $filePath = $dataSource_dirPath . $dataSource_filename;
                $filePaths[] = $filePath;
                $fileURLs[] = my_base_url . my_pligg_base . "/{$dataSource_dir}" . $dataSource_filename;
                $ktrFilePath = mnmpath . "{$newDir}/{$dataSource_filename}.ktr";
                $ktrFileURL = my_base_url . my_pligg_base . "/{$newDir}/{$dataSource_filename}.ktr";
                if (!file_exists($ktrFilePath)) {
                    copy($template, $ktrFilePath);
                }
                $ktrManagers[$dataSource_filename] = new KTRManager($template, $ktrFilePath, array($filePath), $sid, $fileURLs, $ktrFileURL, $ext);
            }
        }
    }
    $_SESSION["ktrArguments_{$sid}"]["ktrManagers"] = serialize($ktrManagers);
    $_SESSION["ktrArguments_{$sid}"]["filenames"] = $filenames;
    $_SESSION["ktrArguments_{$sid}"]["filePaths"] = $filePaths;
    $_SESSION["ktrArguments_{$sid}"]["fileUrls"] = $fileURLs;
}
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:47,代码来源:generate_ktr.php

示例2: upload_0

function upload_0($sid, $uploadTimestamp, $fileType, $excelFileMode, $dbType)
{
    $_SESSION["excelFileMode_{$sid}"] = $excelFileMode;
    // check file type
    $explodeRes = explode(".", $_FILES["upload_file"]["name"]);
    $extension = end($explodeRes);
    $mimes = array('xls', 'xlsx', 'csv', 'sql', 'zip');
    if (count($_FILES) <= 0) {
        $error = "ERROR: No file was uploaded.";
        $_SESSION["upload_file_{$sid}"]['error'] = $error;
    } else {
        if (!in_array($extension, $mimes)) {
            $error = "ERROR: please upload excel, csv, sql, or zip file.";
            $_SESSION["upload_file_{$sid}"]['error'] = $error;
        } else {
            //save upload file
            if ($_FILES['upload_file']['error'] > 0) {
                $error = "ERROR: " . $_FILES['upload_file']['error'] . "</br>";
                $_SESSION["upload_file_{$sid}"]['error'] = $_FILES['upload_file']['error'];
            } else {
                $upload_dir = mnmpath . "upload_raw_data/{$sid}/";
                if (!file_exists($upload_dir)) {
                    mkdir($upload_dir);
                }
                // Delete former files if user upload more than one time.
                if (isset($_SESSION["uploadTimestamp_{$sid}"]) && $_SESSION["uploadTimestamp_{$sid}"] != $uploadTimestamp) {
                    emptyDir($upload_dir);
                }
                $_SESSION["uploadTimestamp_{$sid}"] = $uploadTimestamp;
                // the file name that should be uploaded
                $file_tmp = $_FILES['upload_file']['tmp_name'];
                $raw_file_name = $_FILES['upload_file']['name'];
                $ext = pathinfo($raw_file_name, PATHINFO_EXTENSION);
                $_SESSION["fileExt_{$sid}"] = $ext;
                $upload_path = $upload_dir . $raw_file_name;
                // check upload status
                if (!move_uploaded_file($file_tmp, $upload_path)) {
                    $error = "ERROR: failed to save file.";
                    $_SESSION["upload_file_{$sid}"]['error'] = $_FILES['upload_file']['error'];
                } else {
                    // If a csv file is provided, create a excel file and write the csv value to it.
                    if (strtolower($ext) == 'csv') {
                        // $csvFilePath = $upload_path;
                        // $xlsxFilePath = FileUtil::convertCSVtoXLSX($csvFilePath);
                        // $xlsxFileName = pathinfo($xlsxFilePath, PATHINFO_BASENAME);
                        // $raw_file_name = $xlsxFileName;
                        //unlink($csvFilePath);
                    } else {
                        if (strtolower($ext) == 'zip') {
                            $_SESSION["excelFileMode_{$sid}"] = "append";
                            // If a zip file is provided, unzip all files.
                            $zipFilePath = $upload_path;
                            $zip = new ZipArchive();
                            $res = $zip->open($zipFilePath);
                            if ($res === TRUE) {
                                $zip->extractTo($upload_dir);
                                $zip->close();
                            } else {
                                $error = "ERROR: failed to unzip file.";
                                $_SESSION["upload_file_{$sid}"]['error'] = $error;
                            }
                            // Convert all csv files into xlsx files.
                            $dirFiles = scandir($upload_dir);
                            $i = 1;
                            foreach ($dirFiles as $filename) {
                                $filePath = $upload_dir . $filename;
                                if (FileUtil::isCSVFile($filePath)) {
                                    $_SESSION["fileExt_{$sid}"] = "csv";
                                    break;
                                    // $newFilePath = $upload_dir . $i++ . '.csv';
                                    // rename($filePath, $newFilePath);
                                    // $filePath = $newFilePath;
                                    // $csvFilePath = $filePath;
                                    // $xlsxFilePath = FileUtil::convertCSVtoXLSX($csvFilePath);
                                    // $xlsxFileName = pathinfo($xlsxFilePath, PATHINFO_BASENAME);
                                }
                                //unlink($filePath);
                            }
                        } else {
                            if (strtolower($ext) == 'sql') {
                                try {
                                    $dbImporter = DatabaseImporterFactory::createDatabaseImporter($dbType, $sid, my_pligg_base_no_slash);
                                    $dbImporter->importDbSchema($upload_path);
                                    // Store dump file path for the last step.
                                    $_SESSION["dump_file_{$sid}"] = $upload_path;
                                } catch (Exception $e) {
                                    $_SESSION["upload_file_{$sid}"]['error'] = $e->getMessage();
                                }
                            }
                        }
                    }
                    $loc_msg = "uploaded successfully";
                    $_SESSION["upload_file_{$sid}"]['loc'] = $loc_msg;
                }
            }
        }
    }
    $json_response = array();
    if (isset($_SESSION["upload_file_{$sid}"]['error'])) {
        $json_response['isSuccessful'] = false;
//.........这里部分代码省略.........
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:101,代码来源:acceptFileFromWizard.php


注:本文中的FileUtil::isCSVFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。