Sunday, 13 May 2012

File upload to MyphpAdmin database


<?php
mysql_connect("localhost","","");
mysql_select_db("myconf") or die( "Unable to select database");

if ((($_FILES["file"]["type"] == "application/pdf"))
&& ($_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
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "PDF/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

$order="INSERT INTO submission(author,title,type,file,submissionDate,email,discipline)
VALUES ('$_POST[author]','$_POST[title]','$_POST[type]','$_POST[file]',SYSDATE(),'$_POST[email]','$_POST[discipline]')";


if(mysql_query($order))
{
echo "Submission Succeeded";
}
else
{
echo("Submission failed");
}
?>

No comments:

Post a Comment