本文整理匯總了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);
}
}