PHP: ftp_rename - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ftp_rmdir ftp_rawlist

Last updated: Sat, 27 Jan 2007

view this page in

# ftp_rename

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

ftp_rename -- Переименовывает файл на FTP сервере

## Описание

bool ftp_rename ( resource ftp_stream, string oldname, string newname )

ftp_rename() переименовывает файл или директорию на FTP сервере. ftp_rename() переименовывает файл или директорию `from` в `to`.

## Список параметров

`ftp_stream`

  Идентификатор соединения с FTP сервером

`oldname`

  Старое имя файла/директории

`newname`

  Новое имя файла/директории

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

## Примеры

Пример 1. Пример использования ftp_rename()

`<?php
$old_file = 'somefile.txt.bak';
$new_file = 'somefile.txt';
// установка соединения
$conn_id = ftp_connect($ftp_server);
// проверка имени пользователя и пароля
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// попытка переименовать $olf_file в $new_file
if (ftp_rename($conn_id, $old_file, $new_file)) {
echo "Файл $old_file переименован в $new_file\n";
} else {
echo "Не удалось переименовать $old_file в $new_file\n";
}
// закрытие соединения
ftp_close($conn_id);
?>`

add a note User Contributed Notes
ftp_rename
aventaria at hotmxxx dot com
07-Feb-2007 04:51
`This function isn't only able to rename files, but also folders. And it is not only able to rename them, but also move them, and, in the case of folders, their contents as well (so folders don't have to be empty to move). For example:
<?php
ftp_rename($conn_id, "./dir1/dir2/", "./dir3/");
?>
Now the folder dir2 (which prevously was in folder dir1) has moved to the same folder as dir1, and it has kept its original contents (the content just moved along).`
Hazem dot Khaled at gmail dot com
26-Nov-2006 07:56
`to rename the file or folder you should use ftp_chdir to select the current directory on ftp server or you should write the full path to file in old name and in new name
Ex. 1
<?php
// open the folder that have the file
ftp_chdir($conn_id, '/www/ftp-filemanager/');
// rename the file
ftp_rename($conn_id, 'file1.jpg', 'new_name_4_file.jpg');
?>
or write full path Ex. 2
<?
// rename the file
ftp_rename($conn_id, '/www/ftp-filemanager/file1.jpg', '/www/ftp-filemanager/new_name_4_file.jpg');
?>`
Hugo locobyte at hotmail dot NO_SPAM dot com
22-Nov-2002 12:29
`Using "ftp_rename" to move files to other directories on server ftp
..
...
if(ftp_rename($conn_ftp, $xfiles[$i], "./dirx/".$xfiles[$i])) {
echo "File $xfiles[$i] moved to ./dirx";
} else {
echo "ERROR!!!. The file could not be moved";
}
...
..
#-->>h2m, bye`
29-Sep-2000 04:59
`# Simple example for ftp_rename
# Warning! Not tested...
$server = 'ftp.somewhere.com';
$user = 'anonymous';
$pass = 'someone@somewhere.com';
$original_name = 'file_name.txt';
$new_name = 'new_file_name.txt';
$ftp_connect = ftp_connect ($server)
or die ("Could not connect to $server");
$ftp = ftp_login ($ftp_connect, $user, $pass)
or die ("Authentication failed");
$rename = ftp_rename ($ftp_connect, $original_name, $new_name);
if ($rename)
print "$original_name renamed to $new_name.";
else
print "$original_name could not be renamed...";
ftp_quit ($ftp_connect);`
add a note
ftp_rmdir ftp_rawlist

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 09:32:46 2007 PST