本文整理汇总了PHP中symlink函数的典型用法代码示例。如果您正苦于以下问题:PHP symlink函数的具体用法?PHP symlink怎么用?PHP symlink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了symlink函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupBeforeClass
public static function setupBeforeClass()
{
static::$root = sys_get_temp_dir() . '/insulin';
static::$files = array(static::$root . '/modules/', static::$root . '/sugar/', static::$root . '/sugar/custom/', static::$root . '/sugar/include/', static::$root . '/sugar/include/entryPoint.php', static::$root . '/sugar/include/MVC/', static::$root . '/sugar/include/MVC/SugarApplication.php', static::$root . '/sugar/config.php', static::$root . '/sugar/sugar_version.php');
static::$links = array(static::$root . '/modules' => static::$root . '/sugar/modules', static::$root . '/sugar/custom' => static::$root . '/custom');
if (is_dir(static::$root)) {
static::tearDownAfterClass();
} else {
mkdir(static::$root);
}
foreach (static::$files as $file) {
if ('/' === substr($file, -1) && !is_dir($file)) {
mkdir($file);
} else {
touch($file);
}
}
foreach (static::$links as $target => $link) {
symlink($target, $link);
}
file_put_contents(static::$root . '/sugar/sugar_version.php', '<?php
$sugar_version = \'6.5.3\';
$sugar_db_version = \'6.5.3\';
$sugar_flavor = \'ENT\';
$sugar_build = \'123\';
$sugar_timestamp = \'2008-08-01 12:00am\';
');
}
示例2: cp_r
/**
* Recursive copy function
* @param str src source path
* @param str dst source path
* @return bool
*/
public static function cp_r($src, $dst)
{
if (is_link($src)) {
$l = readlink($src);
if (!symlink($l, $dst)) {
return false;
}
} elseif (is_dir($src)) {
if (!mkdir($dst)) {
return false;
}
$objects = scandir($src);
if ($objects === false) {
return false;
}
foreach ($objects as $file) {
if ($file == "." || $file == "..") {
continue;
}
if (!self::cp_r($src . DIRECTORY_SEPARATOR . $file, $dst . DIRECTORY_SEPARATOR . $file)) {
return false;
}
}
} else {
if (!copy($src, $dst)) {
return false;
}
}
return true;
}
示例3: up
public function up()
{
$old = umask(0);
mkdir(Config::get('upload_dir'), 0777);
umask($old);
symlink(Config::get('upload_dir'), Config::get('public_dir') . '/upload');
}
示例4: processDocument
/**
* Process document and write the result in the document cache.
*
* When the original document is required, create either a symbolic link with the
* original document in the cache dir, or copy it in the cache dir if it's not already done.
*
* This method updates the cache_file_path and file_url attributes of the event
*
* @param DocumentEvent $event Event
*
* @throws \Thelia\Exception\DocumentException
* @throws \InvalidArgumentException , DocumentException
*/
public function processDocument(DocumentEvent $event)
{
$subdir = $event->getCacheSubdirectory();
$sourceFile = $event->getSourceFilepath();
if (null == $subdir || null == $sourceFile) {
throw new \InvalidArgumentException("Cache sub-directory and source file path cannot be null");
}
$originalDocumentPathInCache = $this->getCacheFilePath($subdir, $sourceFile, true);
if (!file_exists($originalDocumentPathInCache)) {
if (!file_exists($sourceFile)) {
throw new DocumentException(sprintf("Source document file %s does not exists.", $sourceFile));
}
$mode = ConfigQuery::read('original_document_delivery_mode', 'symlink');
if ($mode == 'symlink') {
if (false == symlink($sourceFile, $originalDocumentPathInCache)) {
throw new DocumentException(sprintf("Failed to create symbolic link for %s in %s document cache directory", basename($sourceFile), $subdir));
}
} else {
// mode = 'copy'
if (false == @copy($sourceFile, $originalDocumentPathInCache)) {
throw new DocumentException(sprintf("Failed to copy %s in %s document cache directory", basename($sourceFile), $subdir));
}
}
}
// Compute the document URL
$documentUrl = $this->getCacheFileURL($subdir, basename($originalDocumentPathInCache));
// Update the event with file path and file URL
$event->setDocumentPath($documentUrl);
$event->setDocumentUrl(URL::getInstance()->absoluteUrl($documentUrl, null, URL::PATH_TO_FILE));
}
示例5: makeSymlink
protected function makeSymlink($target, $link)
{
if (!@symlink($target, $link)) {
$error = error_get_last();
throw new ErrorException(sprintf("%s: %s -> %s\n", $error['message'], $link, $target));
}
}
示例6: generatePhpbbLink
public function generatePhpbbLink($varValue, DataContainer $dc)
{
if (is_link($dc->activeRecord->phpbb_alias) && readlink($dc->activeRecord->phpbb_alias) == $varValue) {
Message::addInfo("Path to forum already set");
return $varValue;
}
if (is_link($dc->activeRecord->phpbb_alias) !== false && readlink($dc->activeRecord->phpbb_alias) != $varValue) {
Message::addInfo("Removing old link");
unlink($dc->activeRecord->phpbb_alias);
}
Message::addInfo("Trying to set Forum Symlink");
if (file_exists($varValue . "/viewtopic.php")) {
Message::addInfo("Forum found. Setting Link");
$result = symlink($varValue, $dc->activeRecord->phpbb_alias);
if ($result === true) {
Message::addInfo("Link Set");
}
if (!is_link($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') || readlink($dc->activeRecord->phpbb_alias . '/ext/ctsmedia') != "../../contao/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia") {
Message::addInfo("Setting Vendor Link");
symlink(TL_ROOT . "/vendor/ctsmedia/contao-phpbb-bridge-bundle/src/Resources/phpBB/ctsmedia", $dc->activeRecord->phpbb_alias . '/ext/ctsmedia');
}
Message::addInfo("Please activate the contao extension in the phpbb backend");
} else {
//Message::addError("Forum could not be found: ".$varValue . "/viewtopic.php");
throw new Exception("Forum could not be found: " . $varValue . "/viewtopic.php");
}
return $varValue;
}
示例7: publishAction
/**
* 发布素材到开放的目录
*/
public function publishAction()
{
$cli = $this->cli;
$plugins = $this->plugin->getAll();
foreach ($plugins as $plugin) {
$path = $plugin->getBasePath();
// TODO V2 只处理vendor下的插件,直到迁移完毕
if (strpos($path, 'vendor/') !== 0) {
continue;
}
$source = $path . '/public';
if (!is_dir($source)) {
continue;
}
$id = $plugin->getId();
$target = 'plugins/' . $id;
if (is_dir($target)) {
$this->writeln(sprintf('Remove %s', $cli->success($target)));
$this->remove($target);
}
$source = '../' . $source;
$this->writeln(sprintf('Symlink %s to %s', $cli->success($source), $cli->success($target)));
symlink($source, $target);
}
}
示例8: main
function main($source, $dest, $nested = 1)
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// notify user
$this->notify($source, $dest, $nested);
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== ($entry = $dir->read())) {
// Skip pointers
if (substr($entry, 0, 1) == '.' || $entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
$this->main("{$source}/{$entry}", "{$dest}/{$entry}", $nested + 1);
}
// Clean up
$dir->close();
return true;
}
示例9: copyRecursive
/**
* Copies assets recursively
*
* @param $source
* @param $dest
* @param int $permissions
* @return bool
* @internal
*/
private function copyRecursive($source, $dest, $permissions = 0755)
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// Simple copy for a file
if (is_file($source)) {
if (is_file($dest)) {
$this->putWarning("Cannot copy {$source}. File already exists.");
return false;
} else {
return copy($source, $dest);
}
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest, $permissions);
}
// Loop through the folder
$dir = dir($source);
while (false !== ($entry = $dir->read())) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
$this->copyRecursive("{$source}/{$entry}", "{$dest}/{$entry}");
}
// Clean up
$dir->close();
return true;
}
示例10: main
/**
* The method that runs the task
*
* @return void
*/
public function main()
{
parent::main();
// Do we need to create directories?
if (isset($this->map['mkdir'])) {
foreach ($this->map['mkdir'] as $dir) {
$path = realpath($this->destinationBasePath . '/' . $dir);
if (file_exists($path)) {
$this->remove($path);
}
$path = $this->destinationBasePath . '/' . $dir;
$this->log('Creating directory: ' . $path);
mkdir($path);
}
}
foreach ($this->map['symlinks'] as $item) {
$item = explode(' ', $item);
$source = $item[0];
$destination = $item[1];
// Normalise paths
$source = realpath($this->sourceBasePath . '/' . $source);
$destination = rtrim($this->destinationBasePath, '/') . '/' . $destination;
if (!file_exists($source)) {
throw new Exception("Symlink target not found: " . $this->sourceBasePath . '/' . $source, 1);
}
// Check if the destination exists and remove it
if (file_exists($destination)) {
$destination = rtrim($destination, '/');
$this->remove($destination);
}
// Create the new symlink
$this->log('Creating Symlink: ' . $destination);
symlink($source, $destination);
}
}
示例11: recursiveCopy
/**
* Copy a directory recursively and optionally use a extension whitelist
*
* @param string $source
* @param string $dest
* @param array $allowedExtensions
* @return bool|null
*/
protected function recursiveCopy($source, $dest, $allowedExtensions = [])
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// Simple copy for a file
if (is_file($source)) {
// Filter files not matching the extension whitelist
if (!empty($allowedExtensions) and !in_array(pathinfo($source, PATHINFO_EXTENSION), $allowedExtensions)) {
return null;
}
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== ($entry = $dir->read())) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
$this->recursiveCopy("{$source}/{$entry}", "{$dest}/{$entry}", $allowedExtensions);
}
// Clean up
$dir->close();
return true;
}
示例12: setUpBeforeClass
public static function setUpBeforeClass()
{
if ('\\' === DIRECTORY_SEPARATOR) {
self::$linkOnWindows = true;
$originFile = tempnam(sys_get_temp_dir(), 'li');
$targetFile = tempnam(sys_get_temp_dir(), 'li');
if (true !== @link($originFile, $targetFile)) {
$report = error_get_last();
if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
self::$linkOnWindows = false;
}
} else {
@unlink($targetFile);
}
self::$symlinkOnWindows = true;
$originDir = tempnam(sys_get_temp_dir(), 'sl');
$targetDir = tempnam(sys_get_temp_dir(), 'sl');
if (true !== @symlink($originDir, $targetDir)) {
$report = error_get_last();
if (is_array($report) && false !== strpos($report['message'], 'error code(1314)')) {
self::$symlinkOnWindows = false;
}
} else {
@unlink($targetDir);
}
}
}
示例13: symlink
public static function symlink()
{
/* WP FileSystem API does not support symlink creation
global $wp_filesystem;
*/
$muplugin = dirname(WPF2B_PATH) . self::$muplugin_rel;
$symlink = WPMU_PLUGIN_DIR . self::$symlink_rel;
if (!file_exists(WPMU_PLUGIN_DIR)) {
if (!mkdir(WPMU_PLUGIN_DIR, 0755, true)) {
return false;
}
}
if (is_link($symlink) || file_exists($symlink)) {
// Correct symbolic link
if (is_link($symlink) && readlink($symlink) === $muplugin) {
return true;
} else {
/* is_writable() does not detect broken symlinks, unlink() must be @muted
// Incorrect and unwritable
if ( ! is_writable( $symlink ) ) {
return false;
}
*/
// Remove symbolic link
if (!@unlink($symlink)) {
return false;
}
}
}
$linking = symlink($muplugin, $symlink);
return $linking;
}
示例14: create
/**
* Create symlinks from each plugin to app/webroot
*
* @return void
*/
public function create()
{
chdir(realpath(WWW_ROOT));
$paths = $this->_getPaths();
foreach ($paths as $plugin => $config) {
$this->out('Processing plugin: <info>' . $plugin . '</info>');
if (file_exists($config['public'])) {
$this->out(sprintf('--> <warning>Path "%s" already exists</warning>', \Nodes\Common::stripRealPaths($config['public'])));
if (is_link($config['public'])) {
$symlinkTarget = readlink($config['public']);
$this->out('----> Path is already symlink. (' . $symlinkTarget . ')');
if (realpath($config['relative_private']) === realpath($symlinkTarget)) {
$this->out('----> <info>Skipping</info>, Already configured correctly');
continue;
}
$this->out('--> <error>Target is already symlink, but does not have same source</error>');
continue;
} elseif (is_file($config['public'])) {
$this->out('----> Skipping, target is a file');
continue;
} else {
$this->out('----> <error>Skipping, don\'t know how to process file</error>');
continue;
}
}
if (symlink($config['relative_private'], $config['relative_public'])) {
$this->out(sprintf('--> <info>OK</info>, symlink created (%s => %s)', \Nodes\Common::stripRealPaths($config['private']), \Nodes\Common::stripRealPaths($config['public'])));
} else {
$this->out('--> <error>Error</error> Could not create symlink');
}
}
}
示例15: init
public function init()
{
parent::init();
$extJsSrcDir = Yii::getAlias($this->extJsDir);
$extJsSrcExtendDir = Yii::getAlias($this->extJsExtendDir);
$dstDir = Yii::getAlias($this->dstPath);
$extJsDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs';
$extJsExtendDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs-extend';
if (!is_dir($dstDir)) {
if (!is_dir($dstDir)) {
FileHelper::createDirectory($dstDir);
}
}
if (!is_dir($extJsDstDir)) {
symlink($extJsSrcDir, $extJsDstDir);
}
if (!is_dir($extJsExtendDstDir)) {
symlink($extJsSrcExtendDir, $extJsExtendDstDir);
}
$data = DpConfig::find()->all();
$config = [];
foreach ($data as $item) {
$config[$item['name']] = $item['value'];
}
$this->config = $config;
$this->identity = Yii::$app->user->identity;
}