本文整理汇总了PHP中rename_file函数的典型用法代码示例。如果您正苦于以下问题:PHP rename_file函数的具体用法?PHP rename_file怎么用?PHP rename_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rename_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: move_file
function move_file($src, $dest, $filename = null)
{
fileLog(__FUNCTION__, '-', 'ALIAS calling rename_file');
$status = rename_file($src, $dest, $filename);
return $status;
}
示例2: two
public function two($app, $files, $twigArr, $config, $subdir, $filter, $transliteration, $thumbs_path, $get_params, Utility $util, $rfm_subfolder)
{
$files_prevent_duplicate = array();
$html = "";
foreach ($files as $nu => $file_array) {
$file = $file_array['file'];
if ($file == '.' || $file == '..' || is_dir($config['current_path'] . $rfm_subfolder . $subdir . $file) || in_array($file, $config['hidden_files']) || !in_array($util->fix_strtolower($file_array['extension']), $config['ext']) || $filter != '' && $n_files > $file_number_limit_js && stripos($file, $filter) === false) {
continue;
}
$file_path = $config['current_path'] . $rfm_subfolder . $subdir . $file;
//check if file have illegal caracter
$filename = substr($file, 0, '-' . (strlen($file_array['extension']) + 1));
if ($file != $util->fix_filename($file, $transliteration)) {
$file1 = $util->fix_filename($file, $transliteration);
$file_path1 = $this->current_path . $rfm_subfolder . $subdir . $file1;
if (file_exists($file_path1)) {
$i = 1;
$info = pathinfo($file1);
while (file_exists($this->current_path . $rfm_subfolder . $subdir . $info['filename'] . ".[" . $i . "]." . $info['extension'])) {
$i++;
}
$file1 = $info['filename'] . ".[" . $i . "]." . $info['extension'];
$file_path1 = $this->current_path . $rfm_subfolder . $subdir . $file1;
}
$filename = substr($file1, 0, '-' . (strlen($file_array['extension']) + 1));
rename_file($file_path, $util->fix_filename($filename, $transliteration), $transliteration);
$file = $file1;
$file_array['extension'] = $util->fix_filename($file_array['extension'], $transliteration);
$file_path = $file_path1;
}
$is_img = false;
$is_video = false;
$is_audio = false;
$show_original = false;
$show_original_mini = false;
$mini_src = "";
$src_thumb = "";
$extension_lower = $util->fix_strtolower($file_array['extension']);
if ($extension_lower === 'svg') {
//dont try mking thumb for svg file!
} else {
if (in_array($extension_lower, $config['ext_img'])) {
$src = $this->base_url . $this->cur_dir . rawurlencode($file);
$mini_src = $src_thumb = $thumbs_path . $subdir . $file;
//add in thumbs folder if not exist
if (!file_exists($src_thumb)) {
try {
if (!$util->create_img($file_path, $src_thumb, 122, 91)) {
$src_thumb = $mini_src = "";
} else {
$util->new_thumbnails_creation($this->current_path . $rfm_subfolder . $subdir, $file_path, $file, $this->current_path, '', '', '', '', '', '', '', $fixed_image_creation, $fixed_path_from_filemanager, $fixed_image_creation_name_to_prepend, $fixed_image_creation_to_append, $fixed_image_creation_width, $fixed_image_creation_height, $fixed_image_creation_option);
}
} catch (Exception $e) {
$src_thumb = $mini_src = "";
}
}
}
$is_img = true;
//check if is smaller than thumb
list($img_width, $img_height, $img_type, $attr) = @getimagesize($file_path);
if ($img_width < 122 && $img_height < 91) {
$src_thumb = $this->cur_dir . $file;
//var_dump($src_thumb);
$show_original = true;
}
if ($img_width < 45 && $img_height < 38) {
$mini_src = $this->cur_dir . $rfm_subfolder . $subdir . $file;
//var_dump($mini_src);
//$mini_src=$this->current_path.$rfm_subfolder.$subdir.$file."sr";
$show_original_mini = true;
}
$twigArr['img_width'] = $img_width;
$twigArr['img_height'] = $img_height;
$twigArr['src'] = $src;
}
$is_icon_thumb = false;
$is_icon_thumb_mini = false;
$no_thumb = false;
if ($src_thumb == "") {
$no_thumb = true;
if (file_exists('img/' . $config['icon_theme'] . '/' . $extension_lower . ".jpg")) {
$src_thumb = 'img/' . $config['icon_theme'] . '/' . $extension_lower . ".jpg";
} else {
$src_thumb = "img/" . $config['icon_theme'] . "/default.jpg";
}
$is_icon_thumb = true;
}
if ($mini_src == "") {
$is_icon_thumb_mini = false;
}
$class_ext = 0;
if (in_array($extension_lower, $config['ext_video'])) {
$class_ext = 4;
$is_video = true;
} elseif (in_array($extension_lower, $config['ext_img'])) {
$class_ext = 2;
} elseif (in_array($extension_lower, $config['ext_music'])) {
$class_ext = 5;
$is_audio = true;
} elseif (in_array($extension_lower, $config['ext_misc'])) {
//.........这里部分代码省略.........
示例3: restore_datafile
/**
* Restore Backup copy of a dataFile to where it belongs
*
* @since 3.4
*
* @param string $file filepath of data file to restore from backup, locked to GSDATAPATH
* @param bool $delete delete the backup
* @return bool success
*/
function restore_datafile($filepath, $delete = true)
{
if (!filepath_is_safe($filepath, GSDATAPATH)) {
return false;
}
$bakfilepath = getBackupFilePath($filepath);
// backup original before restoring
if (file_exists($filepath)) {
rename_file($bakfilepath, $bakfilepath . '.tmp');
move_file($filepath, $bakfilepath);
$bakfilepath .= '.tmp';
}
if (!$delete) {
return copy_file($bakfilepath, $filepath);
}
return move_file($bakfilepath, $filepath);
}
示例4: check
* Изменение смайла
*/
/**
* Изменение смайла
*/
case 'change':
$uid = !empty($_GET['uid']) ? check($_GET['uid']) : 0;
$code = isset($_POST['code']) ? check(utf_lower($_POST['code'])) : '';
$smile = DBM::run()->selectFirst('smiles', array('smiles_id' => $id));
$checkcode = DBM::run()->selectFirst('smiles', array('smiles_code' => $code, 'smiles_id' => $id));
$checkcode = DBM::run()->queryFirst("SELECT `smiles_id` FROM `smiles` WHERE `smiles_code`=:code AND `smiles_id`<>:id LIMIT 1;", compact('code', 'id'));
$validation = new Validation();
$validation->addRule('equal', array($uid, $_SESSION['token']), 'Неверный идентификатор сессии, повторите действие!')->addRule('not_empty', $smile, 'Не найден смайл для редактирования!')->addRule('empty', $checkcode, 'Смайл с данным кодом уже имеется в списке!')->addRule('string', $code, 'Слишком длинный или короткий код смайла!', true, 1, 20)->addRule('regex', array($code, '|^:+[a-яa-z0-9_\\-/\\(\\)]+$|i'), 'Код смайла должен начинаться с двоеточия. Разрешены буквы, цифры и дефис!', true);
if ($validation->run()) {
if (!preg_match('/[А-Яа-яЁё]/u', $code)) {
$newname = rename_file($smile['smiles_name'], substr($code, 1));
} else {
$newname = $smile['smiles_name'];
}
if (rename(BASEDIR . '/images/smiles/' . $smile['smiles_name'], BASEDIR . '/images/smiles/' . $newname)) {
$smile = DBM::run()->update('smiles', array('smiles_name' => $newname, 'smiles_code' => $code), array('smiles_id' => $id));
clearCache();
notice('Смайл успешно отредактирован!');
redirect("smiles.php?start={$start}");
} else {
show_error('Ошибка! Не удалось переименовать файл смайла!');
}
} else {
show_error($validation->getErrors());
}
render('includes/back', array('link' => 'smiles.php?act=edit&id=' . $id . '&start=' . $start, 'title' => 'Вернуться'));
示例5: define
<th>Real Name</th>
<th>New Name</th>
</tr>
<?php
define('Path', '/rename-file/files/');
//change path with your own
$dir = '/rename-file/files/';
//change path with your own
$files = scandir($dir);
arsort($files);
foreach ($files as $file) {
$new_name = md5_file(Path . $file);
$path_info = pathinfo(Path . $file);
$replace_name = $path_info['filename'];
?>
<tr>
<td align="left"><?php
print $file;
?>
</td>
<td align="left"><?php
print rename_file($replace_name, $new_name, $file);
?>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
示例6: rename_file
function rename_file($fromDir, $new_module)
{
$handle = opendir($fromDir);
$exceptions = array('.', '..');
while (false != ($item = readdir($handle))) {
if (is_dir($fromDir . "/" . $item)) {
if (!in_array($item, $exceptions)) {
$new_module_lower = strtolower($new_module);
$new_item = str_replace("Memday", $new_module, $item);
$new_item = str_replace("memday", $new_module_lower, $new_item);
echo "newItem:" . $new_item . "<br>";
rename($fromDir . "/" . $item, $fromDir . "/" . $new_item);
rename_file($fromDir . "/" . $new_item, $new_module);
}
} else {
$new_module_lower = strtolower($new_module);
$new_module_upper = strtoupper($new_module);
$new_item = str_replace("Memday", $new_module, $item);
$new_item = str_replace("memday", $new_module_lower, $new_item);
rename($fromDir . "/" . $item, $fromDir . "/" . $new_item);
strChangeInThisFile($fromDir . "/" . $new_item, "Memdays", $new_module . "s");
strChangeInThisFile($fromDir . "/" . $new_item, "Memday", $new_module);
strChangeInThisFile($fromDir . "/" . $new_item, "memdays", $new_module_lower . "s");
strChangeInThisFile($fromDir . "/" . $new_item, "memday", $new_module_lower);
strChangeInThisFile($fromDir . "/" . $new_item, "MEMDAYS", $new_module_upper . "S");
strChangeInThisFile($fromDir . "/" . $new_item, "MEMDAY", $new_module_upper);
//strChangeInThisFile($fromDir."/".$new_item,"ec_","vtiger_");
strChangeInThisFile($fromDir . "/" . $new_item, "纪念日", "客户回访");
}
}
closedir($handle);
}
示例7: rename_file
function rename_file($path, $original)
{
$ext = explode(".", $original);
$part1 = time();
$newName = $part1 . "." . $ext[1];
if (file_exists($path . $newName)) {
rename_file($path, $newName);
} else {
return $newName;
}
}
示例8: storeImage
/**
* Save image to uploads folder and change the name to something unique
*
* @param SettingRequest $request
* @param $field
* @return array
*/
private function storeImage(SettingRequest $request, $field)
{
$data = $request->except([$field]);
if ($request->file($field)) {
$file = $request->file($field);
$request->file($field);
$fileName = rename_file($file->getClientOriginalName(), $file->getClientOriginalExtension());
$path = '/uploads/' . str_plural($field);
$move_path = public_path() . $path;
$file->move($move_path, $fileName);
$data[$field] = $path . $fileName;
}
return $data;
}
示例9: getImage
public function getImage($request)
{
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$fileName = rename_file('complogo', $file->getClientOriginalExtension());
$path = '/assets/images/complogo/';
$move_path = public_path() . $path;
$file->move($move_path, $fileName);
Queue::push(ImageResizerJob::class, ['path' => $path, 'filename' => $fileName]);
$data = $request->except('_method', '_token', 'logo');
$data['image_path'] = $path;
$data['image_name'] = $fileName;
return $data;
}
return $request->except('_method', '_token', 'logo');
}
示例10: uploadImage
/**
* Upload the image and return the data
*
* @param $request
* @param string $field
* @return mixed
*/
protected function uploadImage($request, $field)
{
$data = $request->except($field);
if ($file = $request->file($field)) {
$fileName = rename_file($file->getClientOriginalName(), $file->getClientOriginalExtension());
$path = $this->getUploadPath($field);
$file->move(public_path($path), $fileName);
$data[$field] = $path . $fileName;
}
return $data;
}
示例11: upload
/**
* 文件批量上传
* @method upload
* @return [type] [description]
* @author 孙卓豪[@yunyin.org]
* @author 修改NewFuture
*/
public function upload()
{
$uid = use_id();
$files = I('post.files');
if (!$uid) {
/*未登录*/
$this->error(L('UNLOGIN'), __ROOT__);
} elseif (!$files) {
/*未登录*/
$this->error('无文件');
} else {
/*批量获取文件名*/
/*获取文件设置基本信息*/
$File = D('File');
$file_data = array();
$file_data['use_id'] = $uid;
$file_data = $File->create($file_data);
/*获取和更新session中的缓存表信息*/
$upload_list = session('uploads');
session('uploads', null);
$result = array();
foreach ($files as $path) {
$old_name = $upload_list[$path];
if ($old_name) {
$url = 'upload_' . $path;
rename_file('temp_' . $path, $url);
$file_data['url'] = $url;
$file_data['name'] = $old_name;
if ($File->add($file_data)) {
$result[] = array('name' => $old_name, 'r' => 1);
} else {
$result[] = array('name' => $old_name, 'r' => 0);
}
}
}
if (empty($result)) {
$this->error('上传失败');
} else {
$this->success($result);
}
}
}
示例12: create_folder
break;
case 'create_folder':
create_folder(fix_path($path), fix_path($path_thumb));
break;
case 'rename_folder':
$name = fix_filename($name);
if (!empty($name)) {
if (!rename_folder($path, $name)) {
die(lang_Rename_existing_folder);
}
rename_folder($path_thumb, $name);
} else {
die(lang_Empty_name);
}
break;
case 'rename_file':
$name = fix_filename($name);
if (!empty($name)) {
if (!rename_file($path, $name)) {
die(lang_Rename_existing_file);
}
rename_file($path_thumb, $name);
} else {
die(lang_Empty_name);
}
break;
default:
die('wrong action');
break;
}
}
示例13: array
}
$file['info'] = array();
if ($file['tmp_name']) {
$file['info'] = @getimagesize($file['tmp_name']);
}
if (!$err) {
$res = validate_img($file);
if ($res !== true) {
$err = $res;
}
}
// still no error? we can now try and copy the file from the tmp location to the icon dir
if (!$err) {
$newfile = catfile($ps->conf['theme']['icons_dir'], $file['name']);
$overwrote = file_exists($newfile);
$ok = @rename_file($file['tmp_name'], $newfile);
if (!$ok) {
$err = $cms->trans("Error copying new image to icon directory!");
// $err .= is_writable(dirname($newfile)) ? "<br/>" . $cms->trans("Permission Denied") : '';
// if (isset($php_errormsg)) $err .= "<br/>\n" . $php_errormsg;
} else {
$action_result = $cms->trans("File '%s' uploaded successfully!", $file['name']);
if ($overwrote) {
$action_result .= " (" . $cms->trans("Original file was overwritten") . ")";
}
$uploaded_icon = $file['name'];
@chmod(catfile($ps->conf['theme']['icons_dir'], $file['name']), 0644);
}
}
if ($err) {
$form->error('fatal', $err);
示例14: define
}
?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Real Name</th>
<th>New Name</th>
</tr>
<?php
define('Path', 'F:/Tutorials/Node/');
$dir = 'F:/Tutorials/Node/';
$files = scandir($dir);
arsort($files);
foreach ($files as $file) {
?>
<tr>
<td align="left"><?php
print $file;
?>
</td>
<td align="left"><?php
print rename_file($file);
?>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
示例15: getData
/**
* Get data, if image column is passed, upload it
*
* @param $request
* @return mixed
*/
public function getData($request)
{
if (!empty($request->image)) {
$imageColumn = $request->image;
$imageCategory = strtolower($this->model);
if ($imageCategory === 'article') {
$getImageCategory = Category::find($request->category_id);
$imageCategory = strtolower($getImageCategory->title);
}
$data = $request->except($imageColumn);
if ($request->file($imageColumn)) {
$file = $request->file($imageColumn);
$request->file($imageColumn);
$fileName = rename_file($imageCategory, $file->getClientOriginalExtension());
$path = '/assets/images/' . str_slug($imageCategory, '-') . '/';
$move_path = public_path() . $path;
$file->move($move_path, $fileName);
Queue::push(ImageResizerJob::class, ['path' => $path, 'filename' => $fileName]);
$data['image_path'] = $path;
$data['image_name'] = $fileName;
}
return $data;
}
return $request->all();
}