Ok this is how my script looks like at the moment. The file is sent to the folder in question but I dont know how to rename it! How do I for example rename it to test.php when uploading it??

<input type=hidden name=MAX_FILE_SIZE value=930000000 />
<input name=userfile type=file />

<input type=\"submit\" value=\"Submit Picture\" name=\"step\"><input type=\"reset\" value=\"Reset\" name=\"reset\"></TD></TR>

</FORM>";

if ($step)
{
$uploaddir = '/home/blabla/pics/';
$uploadfile = $uploaddir . $HTTP_POST_FILES['userfile']['name'];

print "$HTTP_POST_FILES";
if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadfile)) {

}

    you are best taking the uploaded file and copying it to the new filename copy()

    I think (note think) that an uploaded file is only temporary and is deleted at the end of the script - please correct me if i am wrong here

    so it's best to copy it to a filename that suits you, and a location you want

      In order for me to understand you will need to write down exactly the code that I must use.

      The files are on the server and works to 100% BUT I do not know how to rename them.

      So please post exactly those "things" I need to add in the script to rename the file "test.php"

      THANK YOU!

        i'm not going to write your code for you.

        I can offer you advice, but it will help you learn better if you read and understand why you write something.

        www,php.net/copy

          Then if you wont tell me the code then tell me exactly what the page you linked me to is talking about.

          I dont understand anytjing.

            looking at the manual, there is a better function, rename()

            it take the two arguments, the first is the file you have just uploaded, the second is the name you wish to put it to.

            www.php.net/rename

            Example 1. Example with rename()
            <?php
            rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
            ?>

              Okay thanks so does this look clean and good to you if Im gonna rename it test.php?

              <input type=hidden name=MAX_FILE_SIZE value=930000000 />
              <input name=userfile type=file />

              <input type=\"submit\" value=\"Submit Picture\" name=\"step\"><input type=\"reset\" value=\"Reset\" name=\"reset\"></TD></TR>

              </FORM>";

              if ($step)
              {
              $uploaddir = '/home/blabla/pics/';
              $uploadfile = $uploaddir . $HTTP_POST_FILES['userfile']['name'];

              print "$HTTP_POST_FILES";
              if (move_uploaded_file($HTTP_POST_FILES['userfile']['
              tmp_name'], $uploadfile)) {

              rename("/home/blabla/pics/tmp_file.txt", "/home/blabla/pics/test.php");

              }

                yes, 🙂
                but pop rename in side the } of the if statement and you should be set

                you already had, sorry mis-read slightly

                  Warning: rename(/home/blah/tmp_file.jpg,/home/blah/1.jpg): No such file or directory in /home/blah/submitstuff.php on line 139
                  Array

                  Hmm weird I get that message now.
                  Im basicly trying to rename a jpg file.
                  submitstuff.php is the file that Im using when I press the submit button. Seems like its refering to that instead of the file Im uploading. Or? Hm..

                    i assume you don't actually know the name of the file that will be uploaded, but you are trying to rename/move it to a filename that you want.

                    therefore i think what you need is.

                    rename('$HTTP_POST_FILE[tmp_name]', '/new/destination/file.name')

                      Correct. I do not know what the file name is but I want to re-name it once it is up on my server.
                      This is what I use now:

                      $uploaddir = '/home/public_html/pics/';
                      $uploadfile = $uploaddir . $HTTP_POST_FILES['userfile']['name'];

                      print "$HTTP_POST_FILES";
                      if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $uploadfile)) {
                      }
                      rename('$HTTP_POST_FILE[tmp_name]', '/home/public_html/pics/11111111.jpg');

                      And when I use the above I get this:

                      Array
                      Warning: rename($HTTP_POST_FILES[tmp_name],/home/public_html/pics/11111111.jpg): No such file or directory in /home/public_html/submitstuff.php on line 146

                        The second argument to [man]move_uploaded_file[/man] is where you specify where you want to move the uploaded file to, and the name you want to give it when you put it there.

                        So...

                        move_uploaded_file($_FILES['userfile']['tmp_name'], '/home/public_html/pics/11111111.jpg');

                        Note that I used the $_FILES array which was introduced in PHP 4.1, and inserted the ['userfile'] bit which you left out of your rename() call.

                          Write a Reply...