1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Rename

Discussion in 'PHP' started by MTA, Jan 6, 2009.

  1. #1
    I need help with rename ()

    I need to rename a image.

    test.com/gallery/I/2005/01/01/test.jpg is an example of where the image is at..

    the script is located at. test.com/test/test/rename.php

    rename('./gallery/I/2005/01/01/test.jpg','./gallery/I/2005/01/01/test2.jpg');


    this is not working.. how can i get this to work..
     
    MTA, Jan 6, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <?php
    
    error_reporting( E_ALL );
    
    define( 'DIR_NAME', dirname(__file__) );
    
    $directory = '/gallery/I/2005/01/01/';
    $name = 'test.jpg';
    $new_name = 'test2.jpg';
    
    /* This assumes same directory, change at your leisure. */
    
    if ( !file_exists($file = DIR_NAME . $directory . $name) )
        die( $name . ' does not exist.' );
    
    if ( !rename($file, $new_file = DIR_NAME . $directory . $new_name) )
        die( 'Could not rename ' . $name . '.' . PHP_EOL );
    
    if ( !file_exists($new_file) or file_exists($file) )
        die( 'Could not rename ' . $name . '.' . PHP_EOL );
    PHP:
    Any errors add this code and give me the output.
    var_dump(get_defined_vars());
    PHP:
     
    Danltn, Jan 6, 2009 IP
  3. MTA

    MTA Well-Known Member

    Messages:
    185
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    125
    #3
    does it have to be in the main dir part
     
    MTA, Jan 6, 2009 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    It can be anywhere within the same partition, so yes.
     
    Danltn, Jan 6, 2009 IP
  5. MTA

    MTA Well-Known Member

    Messages:
    185
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    125
    #5
    I have the script in say test.com/member/snapshot/test.php
    so it wont work like that then.
     
    MTA, Jan 6, 2009 IP