Results 1 to 2 of 2

Thread: Renaming a file...

  1. #1
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default Renaming a file...

    I'm trying to rename a uploaded file to the next available ID, but its not renaming the file. Here is the code:
    PHP Code:
    <html>
    <head>
    </head>
    <body>

    <?php
    if (($_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg")
    && (
    $_FILES["file"]["size"] < 200000))
      {
      if (
    $_FILES["file"]["error"] > 0)
        {
        echo 
    "Return Code: " $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo 
    "Upload: " $_FILES["file"]["name"] . "<br />";
        echo 
    "Type: " $_FILES["file"]["type"] . "<br />";
        echo 
    "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo 
    "Temp file: " $_FILES["file"]["tmp_name"] . "<br />";
        if (
    file_exists("upload/" $_FILES["file"]["name"]))
          {
          echo 
    $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
            
    $con mysql_connect("localhost","admin","");
            
    mysql_select_db("markmon_pureadd_upload"$con);
                if (!
    $con)
                  {
                  die(
    'Could not connect: ' mysql_error());
                  }else{
                
    $result mysql_query("SELECT MAX(ID) FROM pictures");

            
    move_uploaded_file($_FILES["file"]["tmp_name"], "uploaded/" $_FILES["file"]["name"]);
          echo 
    "Stored in: " "uploaded/" $_FILES["file"]["name"];
                
    rename("uploaded/" $_FILES['file']['name'] . "",$result++);
                }
          }
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    ?>
    Thanks in advance!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try changing this:

    Code:
    rename("uploaded/" . $_FILES['file']['name'] . "",$result++);
    to this:

    Code:
    rename("uploaded/" . $_FILES['file']['name'], $result++);
    That's the only thing I could see jump out at me.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •