php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48771 rename() between drives error: No error
Submitted: 2009-07-02 07:51 UTC Modified: 2012-08-12 08:37 UTC
From: bugs at thundercall dot dk Assigned: pajoye
Status: Closed Package: Filesystem function related
PHP Version: 5.3CVS-2009-07-02 (snap) OS: win32 only - Windows XP
Private report: No CVE-ID:
 [2009-07-02 07:51 UTC] bugs at thundercall dot dk
Description:
------------
When using rename() from one drive to another drive PHP5.3 & Snap 5.3.1 2009-07-02 fails with error: "No error" and doesn't move the file...

Reproduce code:
---------------
<?php

$old_file = "C:\\Temp\\file.txt";
$new_file = "D:\\Temp\\newfile.txt";

$handle = rename($old_dir.$old_file, $new_dir.$new_file);
if ($handle)
	print "Wuhoo!!";
else
	print "Do'h!";

// $handle = rename($new_dir.$new_file, $old_dir.$old_file); // restore for reruns
?>

Expected result:
----------------
Wuhoo!!

Actual result:
--------------
Warning: rename(C:\Temp\file.txt,D:\Temp\newfile.txt) [function.rename]: No error in D:\home\main\test\rename\index.php on line 6
Do'h!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-02 07:55 UTC] bugs at thundercall dot dk
$handle = rename($old_file, $new_file);

$old_dir & $new_dir was meant for is_dir() checking before moving files,... but as this test didn't needed that, i forgot to remove it from the rename(),.. merged it into $old_file & $new_file.
 [2009-07-02 09:14 UTC] pajoye@php.net
Verified, missing a flag to allow that.
 [2009-07-06 09:09 UTC] pajoye@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-09-06 13:00 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=303070
Log: Per Pierre's e-mail, add a note that the fix for bug #48771 made cross-drive
renames work in Windows.
 [2011-06-12 15:27 UTC] tijs_maas at hotmail dot com
I don't know if i am right but i think i also notice this bug. I do not even use 
absolute paths.

I could use this function wrong or it is the bug, it sais: No error on line 19

 $pathtothisfolder = explode("/", str_replace(array('//', 
'\\'),'/',dirname(__FILE__)));

    $pathtoUpperParent = "";
    for( $i = 0; $i < count($pathtothisfolder) - 2; $i++ ) {
    	$pathtoUpperParent .= $pathtothisfolder[$i]."/";
    }
    $rootname = trim($pathtoUpperParent, versieDirPath());
    
    $parents = count(explode("/", $rootname)) + 2;
    $parentpath = "";
    while ($parents > 0 ) {
    	$parentpath .= "../";
    	$parents --;
    }
    
    // voer de rename operatie uit
    rename($parentpath.$_GET['versie']."/", $parentpath."sdfsdf/" );

The paths i use are without drives, am I also affected by this bug?
 [2011-06-12 15:32 UTC] pajoye@php.net
@tijs_maas at hotmail dot com

Please use a simple:

rename($path1, $path2); as reproduce script, nothing else. That's all this bug is 
about :)
 [2012-08-02 19:25 UTC] luizael dot batista at gmail dot com
hello, when using the rename so 
-->rename(dirname(__FILE__)."/modulos/oldfolder",dirname(__FILE__)."/modulos/newfolder"); works correctly , 

when I add a variable  triggers an alert stating that the volume syntax is incorrect :
rename(dirname(__FILE__)."/modulos/oldfolder",dirname(__FILE__)."/modulos/".$name);
how do I fix this?
 [2012-08-12 08:37 UTC] pajoye@php.net
@luizael dot batista at gmail dot com

Please print out the content of:

dirname(__FILE__)."/modulos/".$name

and paste it here. Whether you use variables or not is not relevant but what is 
in the variables.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 15:01:54 2014 UTC