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


PHP Functions::file_open方法代码示例

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


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

示例1: combine_all_xmls

 function combine_all_xmls($resource_id)
 {
     if ($resource_id == 100) {
         $species_urls = self::get_CONABIO_species_urls();
     }
     if ($resource_id == 106) {
         $species_urls = self::get_Tamborine_species_urls();
     }
     if (!$species_urls) {
         return;
     }
     debug("\n\n Start compiling all XML...");
     $old_resource_path = CONTENT_RESOURCE_LOCAL_PATH . $resource_id . ".xml";
     if (!($OUT = Functions::file_open($old_resource_path, "w+"))) {
         return;
     }
     $str = "<?xml version='1.0' encoding='utf-8' ?>\n";
     $str .= "<response\n";
     $str .= "  xmlns='http://www.eol.org/transfer/content/0.3'\n";
     $str .= "  xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n";
     $str .= "  xmlns:dc='http://purl.org/dc/elements/1.1/'\n";
     $str .= "  xmlns:dcterms='http://purl.org/dc/terms/'\n";
     $str .= "  xmlns:geo='http://www.w3.org/2003/01/geo/wgs84_pos#'\n";
     $str .= "  xmlns:dwc='http://rs.tdwg.org/dwc/dwcore/'\n";
     $str .= "  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n";
     $str .= "  xsi:schemaLocation='http://www.eol.org/transfer/content/0.3 http://services.eol.org/schema/content_0_3.xsd'>\n";
     fwrite($OUT, $str);
     $i = 0;
     $total = sizeof($species_urls);
     foreach ($species_urls as $filename) {
         $i++;
         print "\n {$i} of {$total} ";
         if ($contents = Functions::lookup_with_cache($filename, $this->download_options)) {
             // manual adjustments
             if ($resource_id == 106) {
                 $contents = str_ireplace(array("*"), "", $contents);
             }
             // tamborine mt.
             if ($resource_id == 100) {
                 $contents = str_ireplace("http://creativecommons.org/licenses/by-nc-sa/2.5/mx/", "http://creativecommons.org/licenses/by-nc-sa/2.5/", $contents);
             }
             // conabio.
             if ($xml = simplexml_load_string($contents)) {
                 if ($contents) {
                     $pos1 = stripos($contents, "<taxon>");
                     $pos2 = stripos($contents, "</response>");
                     $str = substr($contents, $pos1, $pos2 - $pos1);
                     fwrite($OUT, $str);
                 }
             } else {
                 print "\n\n [{$filename}] - invalid XML \n\n";
                 continue;
             }
         }
         // if($i >= 5) break; //debug
     }
     fwrite($OUT, "</response>");
     fclose($OUT);
     print "\n All XML compiled\n -end-of-process- \n";
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:60,代码来源:ConabioAPI.php

示例2: start

 function start()
 {
     $topics = array("About the EoE", "Agricultural & Resource Economics", "Biodiversity", "Biology", "Climate Change", "Ecology", "Environmental & Earth Science", "Energy", "Environmental Law & Policy", "Environmental Humanities", "Food", "Forests", "Geography", "Hazards & Disasters", "Health", "Mining & Materials", "People", "Physics & Chemistry", "Pollution", "Society & Environment", "Water", "Weather & Climate", "Wildlife");
     // $topics = array("Biodiversity");
     foreach ($topics as $topic) {
         $this->count = array();
         //it initializes every topic
         if ($OUT = Functions::file_open($this->html_dir . str_replace(" ", "_", $topic) . ".html", "w")) {
         } else {
             exit("\nFile access problem.\n");
         }
         $url = $this->search_url . "&q={$topic}";
         if ($html = Functions::lookup_with_cache($url, $this->download_options)) {
             if (preg_match("/page 1 of (.*?)<\\/title>/ims", $html, $arr)) {
                 $count = $arr[1];
                 for ($i = 1; $i <= $count; $i++) {
                     if ($html = Functions::lookup_with_cache($url . "&page={$i}", $this->download_options)) {
                         if (preg_match_all("/<h1>(.*?)<\\/h1>/ims", $html, $arr)) {
                             print_r($arr[1]);
                             foreach ($arr[1] as $t) {
                                 if (preg_match("/>(.*?)<\\/a>/ims", $t, $arr2)) {
                                     $new_link_text = $arr2[1];
                                     $word_count = str_word_count($new_link_text);
                                     if ($word_count < 3) {
                                         $new_link_text .= " ({$topic})";
                                     }
                                     //--------------
                                     @$this->count[$new_link_text]++;
                                     /* previous 
                                        if($word_count < 3) $c = ($this->count[$new_link_text] > 1 ? $this->count[$new_link_text] : ''); //ternary
                                        else                $c = "";
                                        */
                                     $c = $this->count[$new_link_text] > 1 ? $this->count[$new_link_text] : '';
                                     //ternary
                                     //--------------
                                     $t = str_replace($arr2[1], $new_link_text . " {$c}", $t);
                                 }
                                 fwrite($OUT, $t . "<br>");
                             }
                             // exit;
                         }
                     }
                 }
             }
         }
         fclose($OUT);
     }
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:48,代码来源:EoEarthAPI.php

示例3: extract_archive_file

 function extract_archive_file($dwca_file, $check_file_or_folder_name, $download_options = array('timeout' => 172800, 'expire_seconds' => 0))
 {
     debug("Please wait, downloading resource document...");
     $path_parts = pathinfo($dwca_file);
     $filename = $path_parts['basename'];
     $temp_dir = create_temp_dir() . "/";
     debug($temp_dir);
     if ($file_contents = Functions::lookup_with_cache($dwca_file, $download_options)) {
         $temp_file_path = $temp_dir . "" . $filename;
         debug("temp_dir: {$temp_dir}");
         debug("Extracting... {$temp_file_path}");
         if (!($TMP = Functions::file_open($temp_file_path, "w"))) {
             return;
         }
         fwrite($TMP, $file_contents);
         fclose($TMP);
         sleep(5);
         if (preg_match("/^(.*)\\.(tar.gz|tgz)\$/", $dwca_file, $arr)) {
             $cur_dir = getcwd();
             chdir($temp_dir);
             shell_exec("tar -zxvf {$temp_file_path}");
             chdir($cur_dir);
             $archive_path = str_ireplace(".tar.gz", "", $temp_file_path);
         } elseif (preg_match("/^(.*)\\.(zip)\$/", $dwca_file, $arr) || preg_match("/mcz_for_eol(.*?)/ims", $dwca_file, $arr)) {
             shell_exec("unzip -ad {$temp_dir} {$temp_file_path}");
             $archive_path = str_ireplace(".zip", "", $temp_file_path);
         } else {
             debug("-- archive not gzip or zip. [{$dwca_file}]");
             return;
         }
         debug("archive path: [" . $archive_path . "]");
     } else {
         debug("Connector terminated. Remote files are not ready.");
         return;
     }
     if (file_exists($temp_dir . $check_file_or_folder_name)) {
         return array('archive_path' => $temp_dir, 'temp_dir' => $temp_dir);
     } elseif (file_exists($archive_path . "/" . $check_file_or_folder_name)) {
         return array('archive_path' => $archive_path, 'temp_dir' => $temp_dir);
     } else {
         debug("Can't extract archive file. Program will terminate.");
         return;
     }
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:44,代码来源:INBioAPI.php

示例4: utility_append_text_loop

function utility_append_text_loop()
{
    echo "\n backing up first...";
    $filename = DOC_ROOT . "/public/tmp/mycobank/mycobank_dump.txt";
    copy($filename, DOC_ROOT . "/public/tmp/mycobank/mycobank_dump_backup.txt");
    echo "\n backup done. \n";
    for ($x = 1; $x <= 1; $x++) {
        $str = Functions::format_number_with_leading_zeros($x, "2");
        $filename = DOC_ROOT . "/public/tmp/mycobank/mycobank_dump_add" . $str . ".txt";
        if (!($READ = Functions::file_open($filename, "r"))) {
            return;
        }
        $contents = fread($READ, filesize($filename));
        fclose($READ);
        echo "\n copying... {$filename}";
        $filename = DOC_ROOT . "/public/tmp/mycobank/mycobank_dump.txt";
        echo "\n to... {$filename}\n";
        if (!($WRITE = Functions::file_open($filename, "a"))) {
            return;
        }
        fwrite($WRITE, $contents);
        fclose($WRITE);
    }
}
开发者ID:eliagbayani,项目名称:maps_test,代码行数:24,代码来源:671.php

示例5: access_pesi_service_with_retry

 private function access_pesi_service_with_retry($guid, $type)
 {
     $url = $this->cache_path . $type . "_" . $guid . ".txt";
     $md5 = md5($url);
     $cache1 = substr($md5, 0, 2);
     $cache2 = substr($md5, 2, 2);
     if (!file_exists($this->cache_path . $cache1)) {
         mkdir($this->cache_path . $cache1);
     }
     if (!file_exists($this->cache_path . "{$cache1}/{$cache2}")) {
         mkdir($this->cache_path . "{$cache1}/{$cache2}");
     }
     $filename = $this->cache_path . "{$cache1}/{$cache2}/{$md5}.txt";
     $old_filename = "/Users/eli/eol_old_PESI_cache/" . $type . "_" . $guid . ".txt";
     if (file_exists($old_filename)) {
         $json = file_get_contents($old_filename);
         // echo " --- cache retrieved from old filename";
         return json_decode($json);
     } elseif (file_exists($filename)) {
         $json = file_get_contents($filename);
         // echo " --- cache retrieved";
         return json_decode($json);
     } else {
         //create the cache
         $obj = self::soap_request($guid, $type);
         if (!($file = Functions::file_open($filename, "w"))) {
             return;
         }
         fwrite($file, json_encode($obj));
         fclose($file);
         echo "\n --- cache created [{$filename}]";
         usleep(500000);
         // 5 tenths of a second = 5/10 of a second
         return $obj;
     }
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:36,代码来源:PesiAPI.php

示例6: divide_big_csv_file

 private function divide_big_csv_file($divisor)
 {
     Functions::delete_temp_files($this->OBIS_DATA_PATH . "temp_", "csv");
     $i = 0;
     $line = "";
     $file_count = 0;
     $labels = "";
     foreach (new FileIterator($this->OBIS_DATA_FILE) as $line_number => $linex) {
         $i++;
         $line .= $linex . "\n";
         // FileIterator removes the carriage-return
         if (!$labels) {
             $labels = $line;
             $line = "";
             continue;
         }
         if ($i == $divisor) {
             $i = 0;
             $file_count++;
             if (!($OUT = Functions::file_open($this->OBIS_DATA_PATH . "temp_" . $file_count . ".csv", "w"))) {
                 return;
             }
             fwrite($OUT, $labels);
             fwrite($OUT, $line);
             fclose($OUT);
             $line = "";
         }
     }
     // last writes
     if ($line) {
         $file_count++;
         if (!($OUT = Functions::file_open($this->OBIS_DATA_PATH . "temp_" . $file_count . ".csv", "w"))) {
             return;
         }
         fwrite($OUT, $labels);
         fwrite($OUT, $line);
         fclose($OUT);
     }
     return $file_count;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:40,代码来源:ObisAPI.php

示例7: convert_sheet_to_array

 public function convert_sheet_to_array($spreadsheet, $sheet = NULL, $startRow = NULL, $save_params = false)
 {
     require_once DOC_ROOT . '/vendor/PHPExcel/Classes/PHPExcel.php';
     if (!isset($this->open_spreadsheets)) {
         $this->open_spreadsheets = array();
     }
     $temp = explode('.', $spreadsheet);
     //to avoid E_STRICT warning - only variables can be passed by reference
     $ext = strtolower(end($temp));
     if (isset($this->open_spreadsheets['spreadsheet'])) {
         $objPHPExcel = $this->open_spreadsheets['spreadsheet'];
     } else {
         if ($ext == "xls") {
             $objReader = \PHPExcel_IOFactory::createReader('Excel5');
         } elseif ($ext == "xlsx") {
             $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
         } elseif ($ext == "zip") {
             $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
         } elseif ($ext == "csv") {
             $objReader = new \PHPExcel_Reader_CSV();
         }
         if ($ext != "csv") {
             $objReader->setReadDataOnly(true);
         }
         $objPHPExcel = $objReader->load($spreadsheet);
         $this->open_spreadsheets['spreadsheet'] = $objPHPExcel;
     }
     if (is_null($sheet)) {
         $objWorksheet = $objPHPExcel->getActiveSheet();
     } else {
         if ($sheet + 1 > $objPHPExcel->getSheetCount()) {
             return false;
         }
         $objWorksheet = $objPHPExcel->setActiveSheetIndex($sheet);
     }
     $highestRow = $objWorksheet->getHighestRow();
     // e.g. 10
     $highestColumn = $objWorksheet->getHighestColumn();
     // e.g 'F'
     $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
     // e.g. 5
     $sheet_label = array();
     $sheet_value = array();
     if (is_null($startRow)) {
         $startRow = 1;
     }
     if ($save_params) {
         $FILE = Functions::file_open($save_params['path'] . "/" . $save_params['worksheet_title'] . ".txt", 'w');
     }
     for ($row = $startRow; $row <= $highestRow; ++$row) {
         if ($save_params) {
             $saved_row = array();
         }
         for ($col = 0; $col <= $highestColumnIndex; ++$col) {
             $cell = self::cell_value($objWorksheet, $col, $row, $ext);
             if ($row == $startRow) {
                 $sheet_label[] = $cell;
                 if ($save_params) {
                     $saved_row[] = $cell;
                 }
             } else {
                 $index = trim($sheet_label[$col]);
                 if ($index) {
                     if ($save_params) {
                         $saved_row[] = $cell;
                     } else {
                         $sheet_value[$index][] = $cell;
                     }
                 }
             }
         }
         if ($save_params) {
             fwrite($FILE, implode("\t", $saved_row) . "\n");
         }
     }
     if ($save_params) {
         fclose($FILE);
     }
     return $sheet_value;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:80,代码来源:XLSParser.php

示例8: store_name_to_text_file

 private function store_name_to_text_file($name, $post_name)
 {
     /* This text file will be given to partner so they can fix their names */
     if ($fp = Functions::file_open($this->TEXT_FILE_FOR_DL, "a")) {
         fwrite($fp, $name . "\n");
         fclose($fp);
     }
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:8,代码来源:DiscoverLifeAPIv2.php

示例9: initialize_dump

 private function initialize_dump()
 {
     if (!($h = Functions::file_open($this->dump_file, 'w'))) {
         return;
     }
     fclose($h);
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:7,代码来源:INaturalistAPI.php

示例10: clean_text_file

 private function clean_text_file($file_path)
 {
     echo "\nUpdating {$file_path}";
     //read
     if (!($file = Functions::file_open($file_path, "r"))) {
         return;
     }
     $contents = fread($file, filesize($file_path));
     fclose($file);
     $contents = str_ireplace(chr(10) . chr(13) . "\\", "", $contents);
     //write
     if (!($TMP = Functions::file_open($file_path, "w"))) {
         return;
     }
     fwrite($TMP, $contents);
     fclose($TMP);
     echo "\nChanges saved\n";
     exit;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:19,代码来源:FishBaseArchiveAPI.php

示例11: access_dump_file

 private function access_dump_file($file_path, $is_array = true)
 {
     if (!($file = Functions::file_open($file_path, "r"))) {
         return;
     }
     if ($is_array) {
         $contents = json_decode(fread($file, filesize($file_path)), true);
     } else {
         $contents = fread($file, filesize($file_path));
     }
     fclose($file);
     return $contents;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:13,代码来源:NCBIGGIqueryAPI.php

示例12: generate_text_files

function generate_text_files($text_file)
{
    if ($temp_path = Functions::save_remote_file_to_local($text_file, array('cache' => 1, 'download_timeout_seconds' => 4800, 'download_wait_time' => 300000, 'expire_seconds' => false))) {
        $folder = "exported_titles";
        initialize_text_files($folder);
        $file = Functions::file_open($temp_path, "r");
        $first_row = true;
        $i = 0;
        while (!feof($file)) {
            $cols = explode("\t", fgets($file));
            $title_id = trim(@$cols[0]);
            $title = trim(@$cols[3]);
            if (!$title) {
                continue;
            }
            if ($first_row) {
                $first_row = false;
                continue;
            }
            // print_r($cols); exit;
            echo "[{$title_id}]";
            save_title_to_text($title_id, $title, $folder);
            save_title_to_text($title_id, $title, $folder, true);
        }
        fclose($file);
    }
}
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:27,代码来源:cache_api_searches.php

示例13: assemble_id_list

 private function assemble_id_list()
 {
     if (!($OUT = Functions::file_open($this->tropicos_ids_list_file, "w"))) {
         return;
     }
     $startid = 0;
     // debug orig value 0; 1600267 with mediaURL and <location>; 1201245 with thumbnail size images; 100391155 near the end
     $count = 0;
     while (true) {
         $count++;
         $contents = self::create_cache("id_list", $startid);
         if ($contents) {
             $ids = json_decode($contents, true);
             if ($count % 100 == 0) {
                 echo "\n count:[{$count}] " . count($ids);
             }
             $str = "";
             foreach ($ids as $id) {
                 if (isset($id["Error"])) {
                     return;
                 }
                 // no more ids --- [{"Error":"No names were found"}]
                 if ($id["NameId"]) {
                     $str .= $id["NameId"] . "\n";
                     $startid = $id["NameId"];
                 } else {
                     echo "\n nameid undefined";
                 }
             }
             $startid++;
             // to avoid duplicate ids, set next id to get
             if ($str != "") {
                 fwrite($OUT, $str);
             }
         } else {
             echo "\n --server not accessible-- \n";
             break;
         }
         // if($count == 1300) break; // normal operation
     }
     fclose($OUT);
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:42,代码来源:TropicosArchiveAPI+orig.php

示例14: lookup_with_cache_vimeo_call

 private static function lookup_with_cache_vimeo_call($vimeo, $command, $param, $options = array())
 {
     // default expire time is 15 days
     if (!isset($options['expire_seconds'])) {
         $options['expire_seconds'] = 1296000;
     }
     //debug orig value = 1296000
     if (!isset($options['timeout'])) {
         $options['timeout'] = 240;
     }
     if (!isset($options['cache_path'])) {
         $options['cache_path'] = DOC_ROOT . "tmp/cache/";
     }
     // if(!isset($options['cache_path'])) $options['cache_path'] = "/Volumes/Eli black/eol_cache/";    //debug - only during development
     $url = $command . implode("_", $param);
     $md5 = md5($url);
     $cache1 = substr($md5, 0, 2);
     $cache2 = substr($md5, 2, 2);
     $options['cache_path'] .= "vimeo/";
     if (!file_exists($options['cache_path'])) {
         mkdir($options['cache_path']);
     }
     if (!file_exists($options['cache_path'] . $cache1)) {
         mkdir($options['cache_path'] . $cache1);
     }
     if (!file_exists($options['cache_path'] . "{$cache1}/{$cache2}")) {
         mkdir($options['cache_path'] . "{$cache1}/{$cache2}");
     }
     $cache_path = $options['cache_path'] . "{$cache1}/{$cache2}/{$md5}.cache";
     if (file_exists($cache_path)) {
         $file_contents = file_get_contents($cache_path);
         if (!Functions::is_utf8($file_contents)) {
             $file_contents = utf8_encode($file_contents);
         }
         $obj = json_decode($file_contents);
         if ($file_contents || strval($file_contents) == "0") {
             $file_age_in_seconds = time() - filemtime($cache_path);
             if ($file_age_in_seconds < $options['expire_seconds']) {
                 return $obj;
             }
             if ($options['expire_seconds'] === false) {
                 return $obj;
             }
         }
         @unlink($cache_path);
     }
     if ($obj = $vimeo->call($command, $param)) {
         $file_contents = json_encode($obj);
         if ($FILE = Functions::file_open($cache_path, 'w+')) {
             fwrite($FILE, $file_contents);
             fclose($FILE);
         } else {
             if (!($h = Functions::file_open(DOC_ROOT . "/public/tmp/cant_delete.txt", 'a'))) {
                 return;
             }
             fwrite($h, $cache_path . "\n");
             fclose($h);
         }
         return $obj;
     }
     return false;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:62,代码来源:VimeoAPI.php

示例15: load_zip_contents

 private function load_zip_contents($zip_path, $download_options, $files, $extension)
 {
     $text_path = array();
     $temp_path = create_temp_dir();
     if ($file_contents = Functions::get_remote_file($zip_path, $download_options)) {
         $parts = pathinfo($zip_path);
         $temp_file_path = $temp_path . "/" . $parts["basename"];
         if (!($TMP = Functions::file_open($temp_file_path, "w"))) {
             return;
         }
         fwrite($TMP, $file_contents);
         fclose($TMP);
         $output = shell_exec("unzip {$temp_file_path} -d {$temp_path}");
         if (file_exists($temp_path . "/" . $files[0] . $extension)) {
             foreach ($files as $file) {
                 $text_path[$file] = $temp_path . "/" . $file . $extension;
             }
         } else {
             return;
         }
     } else {
         debug("\n\n Connector terminated. Remote files are not ready.\n\n");
     }
     return $text_path;
 }
开发者ID:eliagbayani,项目名称:maps_test,代码行数:25,代码来源:FEISDataConnector.php


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