File Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
besly98
Forum Newbie
Posts: 15
Joined: Sun Feb 22, 2009 5:50 pm

File Upload

Post by besly98 »

Hi All,

I have a problem. i just cant fix it. this code works fine. it uploads the file and saves it into two tables. i want to add in a random file name. so it renames the file and uploads it to the database. but i cant get it to work. can anybody help me?


Code: Select all

 
<?
 
if ((($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2048000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
 
 
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
  
  $image01 = $_FILES["file"]["name"];
  
 
$con = mysql_connect("*****","*****","*****");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("*****", $con);
 
mysql_query("UPDATE ***** SET *****='".$image01."' WHERE *****='".$results2."'") or die(mysql_error()); 
 
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  
  
  mysql_query("INSERT ***** (*****, *****) VALUES ('".$results2."', '".$image01."')");
  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  
  mysql_close($con);
 
?>
 
 
besly98
Forum Newbie
Posts: 15
Joined: Sun Feb 22, 2009 5:50 pm

Re: File Upload

Post by besly98 »

Right, so i guess the function is in addition at the top and the sql you sent me is to replace all my current mysql stuff?
besly98
Forum Newbie
Posts: 15
Joined: Sun Feb 22, 2009 5:50 pm

Re: File Upload

Post by besly98 »

i been looking at it.. and i cant seem to intergate this. im not to great with php yet.
Post Reply