PHP 8.1.28 Released!

ftp_rename

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_renameFTP sunucusundaki bir dosya veya dizinin adını değiştirir

Açıklama

ftp_rename(FTP\Connection $ftp, string $eskisi, string $yenisi): bool

ftp_rename() işlevi, FTP sunucusundaki belirtilen dosya veya dizinin adını değiştirir.

Bağımsız Değişkenler

ftp_akımı

Bir FTP\Connection nesnesi.

eskisi

Eski dosya/dizin ismi.

yenisi

Yeni dosya/dizin ismi.

Dönen Değerler

Başarı durumunda true, başarısızlık durumunda false döner. Başarısızlık durumunda (varolmayan bir dosyanın adını değiştirmeye çalışmak gibi) bir E_WARNING üretilir.

Sürüm Bilgisi

Sürüm: Açıklama
8.1.0 ftp bağımsız değişkeni artık FTP\Connection nesnesi kabul ediyor; evvelce ftp özkaynağı kabul ediyordu.

Örnekler

Örnek 1 - ftp_rename() örneği

<?php
$eskisi
= 'somefile.txt.bak';
$yenisi = 'somefile.txt';

// Temel bağlantıyı kuralım
$ftp = ftp_connect($ftp_server);

// kullanıcı adı ve parola ile oturum açalım
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// Dosya ismini $yenisi yapalım
if (ftp_rename($ftp, $eskisi, $yenisi)) {
echo
"$eskisi dosyasının ismi $yenisi olarak değiştirildi\n";
} else {
echo
"$eskisi dosyasını ismi $yenisi ile değiştirilirken bir sorun çıktı\n";
}

// bağlantıyı kapatalım
ftp_close($ftp);
?>

add a note

User Contributed Notes 4 notes

up
3
Hazem dot Khaled at gmail dot com
17 years ago
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');
?>
up
3
Hugo locobyte at hotmail dot NO_SPAM dot com
21 years ago
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
up
2
alishahnovin at hotmail dot com
16 years ago
You want to make sure you check the existence of the new name before renaming files, because otherwise you could risk losing files. Just do a simple check with ftp_size with the new name. If it's !=-1, you're going to want to throw some kind of error, otherwise you'll be losing a file...
up
0
aventaria at hotmxxx dot com
17 years ago
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).
To Top