File Upload
Posted: Fri Apr 03, 2009 10:57 am
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?
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);
?>