public function test_directory_clear() { directory_create(self::getDir() . '/another_dir'); file_create(self::getDir() . '/another_file.txt'); $this->assertTrue(count(directory_list(self::getDir())) > 0); directory_clear(self::getDir()); $this->assertEquals(0, count(directory_list(self::getDir()))); }
function export($table, $format, $dbh) { //Здесь закоментить $sth = $dbh->prepare("SELECT * FROM {$table}"); // Это раскоментить // $sth = $dbh->prepare("SELECT * FROM :table"); // $sth->bindParam(':table', $table, PDO::PARAM_STR, 12); $sth->execute(); while ($row = $sth->fetch(PDO::FETCH_NUM)) { $emparray[] = $row; } // Это раскоментить // var_dump($emparray); // exit; if ($format == 'csv') { $file_path = "tmp/{$table}.csv"; $fp = fopen($file_path, 'w+'); foreach ($emparray as $fields) { fputcsv($fp, $fields); } fclose($fp); file_dwonload($file_path); // unlink($file); } if ($format == 'json') { $content = json_encode($emparray); $file_path = file_create($table, $format, $content); file_dwonload($file_path); // unlink($file); } if ($format == 'xml') { $dom = new DOMDocument('1.0', 'UTF-8'); $root = $dom->createElement($table); $dom->appendChild($root); foreach ($emparray as $key => $element) { $table_name = $dom->createElement('table'); $root->appendChild($table_name); foreach ($element as $key2 => $value) { $column = $dom->createElement('column', $value); $table_name->appendChild($column); } } $file_xml = "tmp/{$table}.xml"; $dom->save($file_xml); // header('Content-Type: text/xml'); // echo $dom->saveXML(); file_dwonload($file_xml); } }
/** * @param IHttpRequest $request * @param array $data */ protected function addToTrunk(IHttpRequest $request, array $data) { $trunk = $request->getUrl()->getQuery()->get('trunk', 'default'); if ($trunk !== null || $this->trunkAll) { $trunk = str_replace(['/', '.'], '', $trunk); if (strlen($trunk) > 0) { $path = path($this->trunksPath, $trunk . '.txt'); if (!file_exists($path)) { file_create($path); } file_append($path, s("\n\n%s %s\n\n", date('c'), str_repeat('=', 80))); file_append($path, json_encode($data, JSON_PRETTY_PRINT)); } } }
public function test_file() { $file1 = self::getDir() . '/dir1/foo.txt'; $file2 = self::getDir() . '/dir2/bar.txt'; $file3 = self::getDir() . '/dir2/baz.txt'; $file3_name = 'baz.txt'; $file4 = self::getDir() . '/dir4/yolo.txt'; $this->assertFalse(file_exists($file1)); file_create($file1); file_write($file1, ''); $this->assertTrue(file_exists($file1)); $this->assertEquals('', file_read($file1)); file_write($file1, 'foo'); $this->assertEquals('foo', file_read($file1)); file_append($file1, '_bar'); $this->assertEquals('foo_bar', file_read($file1)); file_prepend($file1, '#'); $this->assertEquals('#foo_bar', file_read($file1)); file_append($file1, '_bar'); file_prepend($file1, '#'); $this->assertEquals('##foo_bar_bar', file_read($file1)); file_append($file1 . '_append', '_bar'); $this->assertEquals(file_read($file1 . '_append'), '_bar'); file_prepend($file1 . '_prepend', '#'); $this->assertEquals(file_read($file1 . '_prepend'), '#'); $this->assertFalse(file_exists($file2)); file_copy($file1, $file2); $this->assertTrue(file_exists($file2)); $this->assertEquals(file_read($file1), file_read($file2)); $this->assertFalse(file_exists($file3)); file_rename($file2, $file3_name); $this->assertFalse(file_exists($file2)); $this->assertTrue(file_exists($file3)); $this->assertEquals(file_read($file1), file_read($file3)); $this->assertFalse(file_exists($file4)); file_move($file3, $file4); $this->assertFalse(file_exists($file3)); $this->assertTrue(file_exists($file4)); $this->assertEquals(file_read($file1), file_read($file4)); file_delete($file4); file_delete($file4); $this->assertFalse(file_exists($file4)); $this->assertEquals(self::getDir() . '/dir1', file_get_directory($file1)); $this->assertEquals('txt', file_get_extension($file1)); $this->assertEquals('foo.txt', file_get_name($file1)); }
/** * Write to a file. * * @param $path * @param $content * * @return bool */ function file_write($path, $content) { file_create($path); return file_put_contents($path, $content) !== false; }
/** * @param $logFilePath */ protected function ensureLogFileExists($logFilePath) { if (!file_exists($logFilePath)) { file_create($logFilePath); } }
function write_config($settings) { global $C; if (!file_exists(FILE_HISTORY)) { file_create(FILE_HISTORY); } unset($settings['r']); $settings['domain'] = preg_replace('~^www\\.~i', '', $_SERVER['HTTP_HOST']); $C = array_merge($C, $settings); check_image_resizer(); $C['base_url'] = preg_replace('~/$~', '', $C['base_url']); $fp = fopen(DIR_LIB . '/config.php', 'r+'); flock($fp, LOCK_EX); fwrite($fp, "<?php\nglobal \$C;\n\$C = array();\n"); foreach ($C as $key => $val) { $val = str_replace(array('\\"', '\\.'), array('"', '.'), addslashes($val)); fwrite($fp, "\$C['{$key}'] = '{$val}';\n"); } fwrite($fp, "?>"); ftruncate($fp, ftell($fp)); flock($fp, LOCK_UN); fclose($fp); $in_settings = "\$C = array('cookie_domain' => '{$C['cookie_domain']}',\n" . "'domain' => '{$C['domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}',\n" . "'flag_filter_no_image' => '{$C['flag_filter_no_image']}');"; $out_settings = "\$C = array('domain' => '{$C['cookie_domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}',\n" . "'distrib_forces' => '{$C['distrib_forces']}',\n" . "'distrib_main' => '{$C['distrib_main']}',\n" . "'distrib_primary' => '{$C['distrib_primary']}',\n" . "'distrib_secondary' => '{$C['distrib_secondary']}',\n" . "'count_clicks' => '{$C['count_clicks']}',\n" . "'fast_click' => '{$C['fast_click']}',\n" . "'trades_satisfied_url' => '{$C['trades_satisfied_url']}',\n" . "'flag_filter_no_image' => '{$C['flag_filter_no_image']}');"; $img_settings = "\$C = array('dir_base' => '" . DIR_BASE . "',\n" . "'domain' => '{$C['cookie_domain']}',\n" . "'keyphrase' => '{$C['keyphrase']}');"; // Write settings to in.php $in = string_format_lf(file_get_contents(FILE_IN_PHP)); $in = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $in_settings . "\n/*#</CONFIG>*/", $in); if (version_compare(PHP_VERSION, '5.1.0', '>=')) { $timezone = date_default_timezone_get(); $in = preg_replace('~/?/?date_default_timezone_set\\(\'.*?\'\\);~', "date_default_timezone_set('{$timezone}');", $in); $in = str_replace('//date_default_timezone_set($timezone);', 'date_default_timezone_set($timezone);', $in); $in = str_replace('//$timezone = date_default_timezone_get();', '$timezone = date_default_timezone_get();', $in); } file_write(FILE_IN_PHP, $in, null); // Write settings to out.php $out = string_format_lf(file_get_contents(FILE_OUT_PHP)); $out = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $out_settings . "\n/*#</CONFIG>*/", $out); file_write(FILE_OUT_PHP, $out, null); // Write settings to image.php $img = string_format_lf(file_get_contents(FILE_IMAGE_PHP)); $img = preg_replace('~/\\*#<CONFIG>\\*/(.*?)/\\*#</CONFIG>\\*/~msi', "/*#<CONFIG>*/\n" . $img_settings . "\n/*#</CONFIG>*/", $img); file_write(FILE_IMAGE_PHP, $img, null); }
function trade_add(&$data, $registered = false) { global $C; require_once 'dirdb.php'; require_once 'mailer.php'; require_once 'template.php'; $t = new Template(); $t->AssignByRef('g_config', $C); $t->AssignByRef('g_trade', $data); $db = new TradeDB(); $db->Add(trade_prepare_data($data)); // Create stats file $packed_record = trade_packed_record(); $fp = fopen(DIR_TRADE_STATS . "/{$data['domain']}", 'w'); for ($i = 0; $i < HOURS_PER_DAY + MINUTES_PER_DAY; $i++) { fwrite($fp, $packed_record, RECORD_SIZE_STATS); } fclose($fp); @chmod(DIR_TRADE_STATS . "/{$data['domain']}", 0666); // Create log files file_create(DIR_TRADE_STATS . "/{$data['domain']}-clicks"); file_create(DIR_TRADE_STATS . "/{$data['domain']}-history"); file_create(DIR_TRADE_STATS . "/{$data['domain']}-in"); file_create(DIR_TRADE_STATS . "/{$data['domain']}-out"); if ($data['flag_confirm']) { require_once 'textdb.php'; $data['confirm_id'] = md5(uniqid(rand(), true)); $confdb = new RegisterConfirmsDB(); $confdb->Add(array('confirm_id' => $data['confirm_id'], 'domain' => $data['domain'], 'timestamp' => time())); $m = new Mailer(); $m->Mail('email-register-confirm.tpl', $t, $data['email'], $data['email']); } else { if ($C['flag_register_email_user'] && !string_is_empty($data['email']) && $registered) { $m = new Mailer(); $m->Mail('email-register-complete.tpl', $t, $data['email'], $data['email']); } if ($C['flag_register_email_admin']) { $m = new Mailer(); $m->Mail('email-register-admin.tpl', $t, $C['email_address'], $C['email_name']); } } }