public function Test_is_dir() { $path = 'invalid path'; $this->assertFalse(AkFtp::is_dir($path)); $path = 'this_is_a_file.txt'; Ak::file_put_contents('this_is_a_file.txt', ''); $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('tmp_test_dir'); Ak::file_put_contents('tmp_test_dir/file_inside.txt', ''); $path = 'tmp_test_dir/file_inside.txt'; $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('real_dir/another/dir'); $path = 'real_dir'; $this->assertTrue(AkFtp::is_dir($path)); $path = 'real_dir/another/dir'; $this->assertTrue(AkFtp::is_dir($path)); AkFtp::delete('real_dir'); AkFtp::delete('this_is_a_file.txt'); AkFtp::delete('tmp_test_dir'); }
function make_dir($path, $options = array()) { $default_options = array('ftp' => defined('AK_UPLOAD_FILES_USING_FTP') && AK_UPLOAD_FILES_USING_FTP, 'base_path' => AK_BASE_DIR); $options = array_merge($default_options, $options); $path = trim(str_replace($options['base_path'], '', $path), DS); if ($options['ftp']) { require_once AK_LIB_DIR . DS . 'AkFtp.php'; $path = trim(str_replace(array(DS, '//'), array('/', '/'), $path), '/'); return AkFtp::make_dir($path); } else { $path = $options['base_path'] . DS . $path; if (!file_exists($path)) { Ak::make_dir(dirname($path), $options); return mkdir($path); } } return false; }
static function make_dir($path, $options = array()) { $default_options = array('ftp' => defined('AK_UPLOAD_FILES_USING_FTP') && AK_UPLOAD_FILES_USING_FTP, 'base_path' => AkConfig::getDir('base')); $options = array_merge($default_options, $options); if (!is_dir($options['base_path']) && !self::make_dir($options['base_path'], array('base_path' => dirname($options['base_path'])))) { trigger_error(Ak::t('Base path %path must exist in order to use it as base_path in self::make_dir()', array('%path' => $options['base_path'])), E_USER_ERROR); } $path = self::getRestrictedPath($path, $options); if ($options['ftp']) { return AkFtp::make_dir($path); } else { $base_path = self::getNormalizedBasePath($options); $path = rtrim($base_path . $path, DS); if (!file_exists($path)) { self::make_dir(dirname($path), $options); return mkdir($path); } else { return true; } } return false; }
public function test_is_dir() { if (!RUN_FTP_TESTS) { return; } $path = 'invalid path'; $this->assertFalse(AkFtp::is_dir($path)); $path = 'this_is_a_file.txt'; AkFileSystem::file_put_contents('this_is_a_file.txt', ''); $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('tmp_test_dir'); AkFileSystem::file_put_contents('tmp_test_dir/file_inside.txt', ''); $path = 'tmp_test_dir/file_inside.txt'; $this->assertFalse(AkFtp::is_dir($path)); AkFtp::make_dir('real_dir/another/dir'); $path = 'real_dir'; $this->assertTrue(AkFtp::is_dir($path)); $path = 'real_dir/another/dir'; $this->assertTrue(AkFtp::is_dir($path)); AkFtp::delete('real_dir'); AkFtp::delete('this_is_a_file.txt'); AkFtp::delete('tmp_test_dir'); AkFtp::delete('cache'); }
function is_dir($path) { if ($ftp_conn = AkFtp::connect()) { $path = AkFtp::unrelativizePath($path); $path = str_replace('\\', '/', $path); $result = @ftp_chdir($ftp_conn, $path); AkFtp::connect(); return $result; } return false; }
static function make_dir($path, $options = array()) { $default_options = array('ftp' => defined('AK_UPLOAD_FILES_USING_FTP') && AK_UPLOAD_FILES_USING_FTP, 'base_path' => AK_BASE_DIR); $options = array_merge($default_options, $options); if (!is_dir($options['base_path']) && !Ak::make_dir($options['base_path'], array('base_path' => dirname($options['base_path'])))) { trigger_error(Ak::t('Base path %path must exist in order to use it as base_path in Ak::make_dir()', array('%path' => $options['base_path'])), E_USER_ERROR); } $path = trim(str_replace($options['base_path'], '', $path), DS); if ($options['ftp']) { $path = trim(str_replace(array(DS, '//'), array('/', '/'), $path), '/'); return AkFtp::make_dir($path); } else { $base_path = AK_WIN && empty($options['base_path']) ? '' : $options['base_path'] . DS; $path = rtrim($base_path . $path, DS); if (!file_exists($path)) { Ak::make_dir(dirname($path), $options); return mkdir($path); } else { return true; } } return false; }