Php move and rename file
Use for both renaming and moving files, rename() takes two parameters: the original filename and the new filename you wish to use. Rename() can rename/move files across directories and drives, and will return true on success or false otherwise. Here is an example:
If you had $filename set to c:\\windows\\myfile.txt, the above script would move that file to c:\\windows\\myfile.txt.old. Author's Note: rename() should be used to move ordinary files, and not files uploaded through a form. The reason for this is because there is a special function, called move_uploaded_file(), which checks to make sure the file has indeed been uploaded before moving it - this stops people trying to hack your server into making private files visible. You can perform this check yourself if you like by calling the is_uploaded_file() function. Copyright ©2015 Paul Hudson. Follow me: @twostraws. (PHP 4, PHP 5, PHP 7, PHP 8) rename — Renames a file or directory Descriptionrename(string Parametersfrom The old name.
to The new name.
context A context stream resource. Return Values Returns ExamplesExample #1 Example with rename()
See Also
andrew at 21cv dot co dot uk ¶ 12 years ago
("/folder/file.ext", "newfile.ext");?> ben at indietorrent dot org ¶ 7 years ago
mike ¶ 8 years ago
pcdinh at phpvietnam dot net ¶ 13 years ago
michael-nospam at sal dot mik dot hyperlink dot net dot au ¶ 22 years ago
Whooptydoo ¶ 14 years ago
Martin Pelletier ¶ 11 years ago
php at froghh dot de ¶ 16 years ago
php at stock-consulting dot com ¶ 16 years ago
sophie at sitadelle dot com ¶ 18 years ago
andrew at iwebsolutions dot co dot uk ¶ 13 years ago
$return_val == 0) {
Eric (Themepark.com) ¶ 15 years ago
bcag2 at free dot fr ¶ 9 years ago
=iconv("UTF-8", "CP1252", "C:\\wamp\\www\\tést.txt"); tomfelker at gmail dot com ¶ 17 years ago
David Thole (root at thedarktrumpet.com) ¶ 15 years ago
php-public at macfreek dot nl ¶ 16 years ago
tbrillon at gmail dot com ¶ 17 years ago
dev at islam-soft dot com ¶ 15 years ago
eregi("\.$ext1",$file)) { # Look at only files with a pre-defined extension ddoyle [at] canadalawbook [dot] ca ¶ 17 years ago
Robert ¶ 8 years ago
= 'testFile.txt'; PHP at Drarok dot com ¶ 16 years ago
lord dot dracon at gmail dot com ¶ 4 years ago
tomv ¶ 5 years ago
mike at mbfisher dot com ¶ 7 years ago
Morteza ¶ 12 years ago
getDirectory( $path = '.', $level = 0 ){$ignore = array( 'cgi-bin', '.', '..' );$dh = @opendir( $path ); pearcec at commnav dot com ¶ 21 years ago
|