本文整理汇总了PHP中rename函数的典型用法代码示例。如果您正苦于以下问题:PHP rename函数的具体用法?PHP rename怎么用?PHP rename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* {@inheritdoc}
*/
public function run()
{
if (is_null($this->dst) || "" === $this->dst) {
return Result::error($this, 'You must specify a destination file with to() method.');
}
if (!$this->checkResources($this->files, 'file')) {
return Result::error($this, 'Source files are missing!');
}
if (file_exists($this->dst) && !is_writable($this->dst)) {
return Result::error($this, 'Destination already exists and cannot be overwritten.');
}
$dump = '';
foreach ($this->files as $path) {
foreach (glob($path) as $file) {
$dump .= file_get_contents($file) . "\n";
}
}
$this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
$dst = $this->dst . '.part';
$write_result = file_put_contents($dst, $dump);
if (false === $write_result) {
@unlink($dst);
return Result::error($this, 'File write failed.');
}
// Cannot be cross-volume; should always succeed.
@rename($dst, $this->dst);
return Result::success($this);
}
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$remoteFilename = 'http://get.insight.sensiolabs.com/insight.phar';
$localFilename = $_SERVER['argv'][0];
$tempFilename = basename($localFilename, '.phar') . '-temp.phar';
try {
copy($remoteFilename, $tempFilename);
if (md5_file($localFilename) == md5_file($tempFilename)) {
$output->writeln('<info>insight is already up to date.</info>');
unlink($tempFilename);
return;
}
chmod($tempFilename, 0777 & ~umask());
// test the phar validity
$phar = new \Phar($tempFilename);
// free the variable to unlock the file
unset($phar);
rename($tempFilename, $localFilename);
$output->writeln('<info>insight updated.</info>');
} catch (\Exception $e) {
if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
throw $e;
}
unlink($tempFilename);
$output->writeln('<error>The download is corrupt (' . $e->getMessage() . ').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
}
}
示例3: __construct
/**
* Constructor
*
* @param array $data the form data as name => value
* @param string|null $suffix the optional suffix for the tmp file
* @param string|null $suffix the optional prefix for the tmp file. If null 'php_tmpfile_' is used.
* @param string|null $directory directory where the file should be created. Autodetected if not provided.
* @param string|null $encoding of the data. Default is 'UTF-8'.
*/
public function __construct($data, $suffix = null, $prefix = null, $directory = null, $encoding = 'UTF-8')
{
if ($directory === null) {
$directory = self::getTempDir();
}
$suffix = '.fdf';
$prefix = 'php_pdftk_fdf_';
$this->_fileName = tempnam($directory, $prefix);
$newName = $this->_fileName . $suffix;
rename($this->_fileName, $newName);
$this->_fileName = $newName;
$fields = '';
foreach ($data as $key => $value) {
// Create UTF-16BE string encode as ASCII hex
// See http://blog.tremily.us/posts/PDF_forms/
$utf16Value = mb_convert_encoding($value, 'UTF-16BE', $encoding);
/* Also create UTF-16BE encoded key, this allows field names containing
* german umlauts and most likely many other "special" characters.
* See issue #17 (https://github.com/mikehaertl/php-pdftk/issues/17)
*/
$utf16Key = mb_convert_encoding($key, 'UTF-16BE', $encoding);
// Escape parenthesis
$utf16Value = strtr($utf16Value, array('(' => '\\(', ')' => '\\)'));
$fields .= "<</T(" . chr(0xfe) . chr(0xff) . $utf16Key . ")/V(" . chr(0xfe) . chr(0xff) . $utf16Value . ")>>\n";
}
// Use fwrite, since file_put_contents() messes around with character encoding
$fp = fopen($this->_fileName, 'w');
fwrite($fp, self::FDF_HEADER);
fwrite($fp, $fields);
fwrite($fp, self::FDF_FOOTER);
fclose($fp);
}
示例4: writeFile
/**
* Writes file in a save way to disk
*
* @param string $_filepath complete filepath
* @param string $_contents file content
* @return boolean true
*/
public static function writeFile($_filepath, $_contents, $smarty)
{
$old_umask = umask(0);
$_dirpath = dirname($_filepath);
// if subdirs, create dir structure
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
mkdir($_dirpath, $smarty->_dir_perms, true);
}
// write to tmp file, then move to overt file lock race condition
$_tmp_file = tempnam($_dirpath, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$_tmp_file = $_dirpath . DS . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
throw new SmartyException("unable to write file {$_tmp_file}");
return false;
}
}
fwrite($fd, $_contents);
fclose($fd);
// remove original file
if (file_exists($_filepath)) {
@unlink($_filepath);
}
// rename tmp file
rename($_tmp_file, $_filepath);
// set file permissions
chmod($_filepath, $smarty->_file_perms);
umask($old_umask);
return true;
}
示例5: onKernelRequest
public function onKernelRequest($event)
{
switch (true) {
case HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType():
case $this->container->get('kernel')->getEnvironment() == 'dev':
return;
}
$url = $this->container->get('request')->getUri();
$path = $this->container->getParameter('kernel.cache_dir');
$old_path = $this->container->getParameter('kernel.cache_dir') . '_old';
$hash_file = $this->container->getParameter('kernel.cache_dir') . '/config_hash';
$hash_value = $this->getHash();
if (!file_exists($hash_file)) {
$this->writeHashFile($hash_file, $hash_value);
return;
} else {
$old = file_get_contents($hash_file);
if ($old == $hash_value) {
return;
}
$this->writeHashFile($hash_file, $hash_value);
}
if (is_dir($old_path)) {
$this->container->get('filesystem')->remove($old_path);
}
rename($path, $old_path);
$this->container->get('filesystem')->remove($old_path);
header('Location: ' . $url);
exit;
}
示例6: smarty_core_write_file
/**
* write out a file to disk
*
* @param string $filename
* @param string $contents
* @param boolean $create_dirs
* @return boolean
*/
function smarty_core_write_file($params, &$smarty)
{
$_dirname = dirname($params['filename']);
if ($params['create_dirs']) {
$_params = array('dir' => $_dirname);
require_once SMARTY_CORE_DIR . 'core.create_dir_structure.php';
smarty_core_create_dir_structure($_params, $smarty);
}
// write to tmp file, then rename it to avoid file locking race condition
$_tmp_file = tempnam($_dirname, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$smarty->trigger_error("problem writing temporary file '{$_tmp_file}'");
return false;
}
}
fwrite($fd, $params['contents']);
fclose($fd);
if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
// On platforms and filesystems that cannot overwrite with rename()
// delete the file before renaming it -- because windows always suffers
// this, it is short-circuited to avoid the initial rename() attempt
@unlink($params['filename']);
@rename($_tmp_file, $params['filename']);
}
@chmod($params['filename'], $smarty->_file_perms);
return true;
}
示例7: save_page
function save_page($page)
{
$file_content = "";
// set content
foreach ($page as $key => $value) {
if ($value) {
if ($key == 'slug') {
$file_content .= "{: " . $key . " :} " . strtolower(url_title($value)) . "\n";
} else {
$file_content .= "{: " . $key . " :} " . $value . "\n";
}
}
}
// if it is placed as subpage
if (!empty($page['parent'])) {
// if parent still as standalone file (not in folder)
if (file_exists(PAGE_FOLDER . $page['parent'] . '.md')) {
// create folder and move the parent inside
mkdir(PAGE_FOLDER . $page['parent'], 0775);
rename(PAGE_FOLDER . $page['parent'] . '.md', PAGE_FOLDER . $page['parent'] . '/index.md');
// create index.html file
copy(PAGE_FOLDER . 'index.html', PAGE_FOLDER . $page['parent'] . '/index.html');
}
}
if (write_file(PAGE_FOLDER . $page['parent'] . '/' . $page['slug'] . '.md', $file_content)) {
$this->pusaka->sync_page();
return true;
} else {
return false;
}
}
示例8: rename
private function rename()
{
$sql = "select * from t_wz order by id DESC limit 1";
$info2 = $GLOBALS['dbk']->prepare($sql);
$info2->execute();
foreach ($info2 as $value) {
$this->newname = $value['id'] + 1;
}
switch ($this->file['type']) {
case 'image/jpeg':
$this->newname = $this->newname . ".jpg";
break;
case 'image/png':
$this->newname = $this->newname . ".png";
break;
case 'image/gif':
$this->newname = $this->newname . ".gif";
break;
}
$oldname = $this->path . "/" . $this->file['name'];
$newname = $this->path . "/" . $this->newname;
if (rename($oldname, $newname)) {
}
return true;
}
示例9: rotate
protected function rotate($logfile)
{
$rotatedLogfile = $logfile . '.1';
rename($logfile, $rotatedLogfile);
$msg = 'Log file "' . $logfile . '" was over ' . $this->max_log_size . ' bytes, moved to "' . $rotatedLogfile . '"';
\OC_Log::write('OC\\Log\\Rotate', $msg, \OC_Log::WARN);
}
示例10: gridextjs_deprecated
function gridextjs_deprecated()
{
if (file_exists(dirname(__FILE__) . '/../../modules/gridextjs')) {
return rename(dirname(__FILE__) . '/../../modules/gridextjs', dirname(__FILE__) . '/../../modules/gridextjs.deprecated');
}
return true;
}
示例11: smarty_core_write_file
/**
* write out a file to disk
*
* @param string $filename
* @param string $contents
* @param boolean $create_dirs
* @return boolean
*/
function smarty_core_write_file($params, &$smarty)
{
$_dirname = dirname($params['filename']);
if ($params['create_dirs']) {
$_params = array('dir' => $_dirname);
require_once SMARTY_CORE_DIR . 'core.create_dir_structure.php';
smarty_core_create_dir_structure($_params, $smarty);
}
// write to tmp file, then rename it to avoid
// file locking race condition
$_tmp_file = tempnam($_dirname, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$smarty->trigger_error("problem writing temporary file '{$_tmp_file}'");
return false;
}
}
fwrite($fd, $params['contents']);
fclose($fd);
// Delete the file if it allready exists (this is needed on Win,
// because it cannot overwrite files with rename()
if (file_exists($params['filename'])) {
@unlink($params['filename']);
}
@rename($_tmp_file, $params['filename']);
@chmod($params['filename'], $smarty->_file_perms);
return true;
}
示例12: fetch
public function fetch()
{
if ($this->request->method('post')) {
$this->dir_delete($this->compiled_dir, false);
$old_names = $this->request->post('old_name');
$new_names = $this->request->post('new_name');
if (is_array($old_names)) {
foreach ($old_names as $i => $old_name) {
$new_name = preg_replace("/[^a-zA-Z0-9\\-\\_]/", "", $new_names[$i]);
if (is_writable($this->themes_dir) && is_dir($this->themes_dir . $old_name) && !is_file($this->themes_dir . $new_name) && !is_dir($this->themes_dir . $new_name)) {
rename($this->themes_dir . $old_name, $this->themes_dir . $new_name);
if ($this->settings->theme == $old_name) {
$this->settings->theme = $new_name;
}
} elseif (is_file($this->themes_dir . $new_name) && $new_name != $old_name) {
$message_error = 'name_exists';
}
}
}
$action = $this->request->post('action');
$action_theme = $this->request->post('theme');
switch ($this->request->post('action')) {
case 'set_main_theme':
$this->settings->theme = $action_theme;
break;
case 'clone_theme':
$new_name = $this->settings->theme;
while (is_dir($this->themes_dir . $new_name) || is_file($this->themes_dir . $new_name)) {
if (preg_match('/(.+)_([0-9]+)$/', $new_name, $parts)) {
$new_name = $parts[1] . '_' . ($parts[2] + 1);
} else {
$new_name = $new_name . '_1';
}
}
$this->dir_copy($this->themes_dir . $this->settings->theme, $this->themes_dir . $new_name);
@unlink($this->themes_dir . $new_name . '/locked');
$this->settings->theme = $new_name;
break;
case 'delete_theme':
$this->dir_delete($this->themes_dir . $action_theme);
if ($action_theme == $this->settings->theme) {
$t = current($this->get_themes());
$this->settings->theme = $t->name;
}
break;
}
}
$themes = $this->get_themes();
// Если нет прав на запись - передаем в дизайн предупреждение
if (!is_writable($this->themes_dir)) {
$this->design->assign('message_error', 'permissions');
}
$current_theme = new stdClass();
$current_theme->name = $this->settings->theme;
$current_theme->locked = is_file($this->themes_dir . $current_theme->name . '/locked');
$this->design->assign('theme', $current_theme);
$this->design->assign('themes', $themes);
$this->design->assign('themes_dir', $this->themes_dir);
return $this->design->fetch('theme.tpl');
}
示例13: move
/**
* Resize a file uploaded
* @param string $path Path of the data, for instance to upload the file in data['Movie']['picture'] path would be Movie.picture
* @param string $dest Where to save the uploaded file
* @param integer $width
* @param integer $height
* @return boolean True if the image is uploaded.
*/
public function move($path, $dest, $width = 0, $height = 0)
{
$file = Hash::get($this->controller->request->data, $path);
if (empty($file['tmp_name'])) {
return false;
}
$tmp = TMP . $file['name'];
move_uploaded_file($file['tmp_name'], $tmp);
$info = pathinfo($file['name']);
$destinfo = pathinfo($dest);
$directory = dirname(IMAGES . $dest);
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
if ($info['extension'] == $destinfo['extension'] && $width == 0) {
rename($tmp, IMAGES . $dest);
return true;
}
if (!file_exists($dest_file)) {
require_once APP . 'Plugin' . DS . 'Media' . DS . 'Vendor' . DS . 'imagine.phar';
$imagine = new Imagine\Gd\Imagine();
$imagine->open($tmp)->thumbnail(new Imagine\Image\Box($width, $height), Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND)->save(IMAGES . $dest, array('quality' => 90));
}
return true;
}
示例14: action_editer_auteur_dist
/**
* Editer ou créer un auteur
*
* @link http://doc.spip.org/@action_editer_auteur_dist
* @global array $GLOBALS['visiteur_session']
* @param array $arg
* @return array
*/
function action_editer_auteur_dist($arg = null)
{
if (is_null($arg)) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
}
// si id_auteur n'est pas un nombre, c'est une creation
if (!($id_auteur = intval($arg))) {
if (($id_auteur = auteur_inserer()) > 0) {
# cf. GROS HACK
# recuperer l'eventuel logo charge avant la creation
# ils ont un id = 0-id_auteur de la session
$id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur'];
$chercher_logo = charger_fonction('chercher_logo', 'inc');
if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'on')) {
rename($logo, str_replace($id_hack, $id_auteur, $logo));
}
if (list($logo) = $chercher_logo($id_hack, 'id_auteur', 'off')) {
rename($logo, str_replace($id_hack, $id_auteur, $logo));
}
}
}
// Enregistre l'envoi dans la BD
$err = "";
if ($id_auteur > 0) {
$err = auteur_modifier($id_auteur);
}
if ($err) {
spip_log("echec editeur auteur: {$err}", _LOG_ERREUR);
}
return array($id_auteur, $err);
}
示例15: fromSong
/**
* Generate the downloadable path for a song.
*
* @param Song $song
*
* @return string
*/
protected function fromSong(Song $song)
{
if ($s3Params = $song->s3_params) {
// The song is hosted on Amazon S3.
// We download it back to our local server first.
$localPath = rtrim(sys_get_temp_dir(), '/') . '/' . basename($s3Params['key']);
$url = $song->getObjectStoragePublicUrl();
abort_unless($url, 404);
// The following function require allow_url_fopen to be ON.
// We're just assuming that to be the case here.
copy($url, $localPath);
} else {
// The song is hosted locally. Make sure the file exists.
abort_unless(file_exists($song->path), 404);
$localPath = $song->path;
}
// The BinaryFileResponse factory only accept ASCII-only file names.
if (ctype_print($localPath)) {
return $localPath;
}
// For those with high-byte characters in names, we copy it into a safe name
// as a workaround.
$newPath = rtrim(sys_get_temp_dir(), '/') . '/' . utf8_decode(basename($song->path));
if ($s3Params) {
// If the file is downloaded from S3, we rename it directly.
// This will save us some disk space.
rename($localPath, $newPath);
} else {
// Else we copy it to another file to not mess up the original one.
copy($localPath, $newPath);
}
return $newPath;
}