SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: rename()

  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rename()

    Hi,

    I'm trying to rename a temporary file I've created but it doesn't work. Says the file doesn't exist. When I do a file_exists() on the file, it also says it doesn't exist. Yet I can see the file on the server....

    Any ideas?

    //create temp file
    $tmp = time().".xml";
    $handle = fopen($tmp, "w");
    fwrite($handle, "data goes here");
    fclose($handle);

    //rename temp file
    rename($tmp, "data.xml");

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your code worked fine for me. Result was a file called data.xml with "data goes here" as the content.
    Are you getting an error message?

    edit
    after refreshing the script an error was produced because data.xml already existed at this stage. Is this the error you got?

  3. #3
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No such file or directory

    That's the error I'm getting on the rename

    You get the already exists error in windows.

  4. #4
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried your code again, on my linux host and it worked fine.
    Each time I executed the script it overwrote data.xml

  5. #5
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any ideas why it doesn't work on mine then?

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im going to guess because the code you have posted, is not the code you are actually running.

    maybe you dont realize it, or maybe you have ommited some code that you felt was irrelevant.

    in any case, try the code, exactly as you have posted it. make a new script for it.

  7. #7
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, you're right.

    I'm an idiot. All working now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •