rename function

Discussion in 'PHP' started by lammspillning, Aug 14, 2007.

  1. #1
    I´m new to php and dont really know how to do this..
    I have some code for a file upload:

    <?php
    //create the directory if doesn't exists (should have write permissons)
    if(!is_dir("./files")) mkdir("./files", 0755);
    //move the uploaded file
    move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/".$_FILES['Filedata']['name']);
    chmod("./files/".$_FILES['Filedata']['name'], 0777);
    ?>

    My question is how do I write some code that rename the uploade file to a specific new filename, and on which line should the code be?

    //thnx
     
    lammspillning, Aug 14, 2007 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    replace:
    "./files/".$_FILES['Filedata']['name']
    with:
    "./files/theFileNameYouWant.extension"

    like this for example:

    move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/myImage.png");
    PHP:
     
    nabil_kadimi, Aug 14, 2007 IP
  3. lammspillning

    lammspillning Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ok thanx nabil! works perfect!
     
    lammspillning, Aug 14, 2007 IP