本文整理汇总了PHP中stored_file::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP stored_file::rename方法的具体用法?PHP stored_file::rename怎么用?PHP stored_file::rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stored_file
的用法示例。
在下文中一共展示了stored_file::rename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmldb_hotpot_move_file
/**
* xmldb_hotpot_move_file
*
* move a file or folder (within the same context)
* if $file is a directory, then all subfolders and files will also be moved
* if the destination file/folder already exists, then $file will be deleted
*
* @param stored_file $file
* @param string $new_filepath
* @param string $new_filename (optional, default='')
* @return void, but may update filearea
*/
function xmldb_hotpot_move_file($file, $new_filepath, $new_filename = '')
{
$fs = get_file_storage();
$contextid = $file->get_contextid();
$component = $file->get_component();
$filearea = $file->get_filearea();
$itemid = $file->get_itemid();
$old_filepath = $file->get_filepath();
$old_filename = $file->get_filename();
if ($file->is_directory()) {
$children = $fs->get_directory_files($contextid, $component, $filearea, $itemid, $old_filepath);
$old_filepath = '/^' . preg_quote($old_filepath, '/') . '/';
foreach ($children as $child) {
xmldb_hotpot_move_file($child, preg_replace($old_filepath, $new_filepath, $child->get_filepath(), 1));
}
}
if ($new_filename == '') {
$new_filename = $old_filename;
}
if ($fs->file_exists($contextid, $component, $filearea, $itemid, $new_filepath, $new_filename)) {
$file->delete();
// new file already exists
} else {
$file->rename($new_filepath, $new_filename);
}
}