|
ftp_rename
Renames a file or a directory on the FTP server
(PHP 4, PHP 5)
Example 745. ftp_rename() example<?php Code Examples / Notes » ftp_renamehugo locobyte
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 hazem dot khaled
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'); ?> aventaria
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). 29-sep-2000 12: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); |
Change Languageftp_alloc ftp_cdup ftp_chdir ftp_chmod ftp_close ftp_connect ftp_delete ftp_exec ftp_fget ftp_fput ftp_get_option ftp_get ftp_login ftp_mdtm ftp_mkdir ftp_nb_continue ftp_nb_fget ftp_nb_fput ftp_nb_get ftp_nb_put ftp_nlist ftp_pasv ftp_put ftp_pwd ftp_quit ftp_raw ftp_rawlist ftp_rename ftp_rmdir ftp_set_option ftp_site ftp_size ftp_ssl_connect ftp_systype |