need the path for the upload stored in a table
The code I am using to upload the files is this
<?php
$con = mysql_connect("localhost","user name","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("server name", $con);
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
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("VPics/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"VPics/" . $_FILES["file"]["name"]);
echo "Stored in: " . "VPics/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
I am trying to insert the resulting path into a table and not finding the propper tutorials to help me with this. I have tried using insert codes after the "move_uploaded_file" section of the code, however the result has been that the page does not refresh after the submit button is hit and when I put in a check for an error it came back with an "invalid file" without the insert code the file does upload propperly to the destination folder.
Subject
Written By
Posted
need the path for the upload stored in a table
November 16, 2012 03:16PM
November 16, 2012 05:51PM
November 16, 2012 10:07PM
November 16, 2012 11:36PM
November 17, 2012 02:41PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.