I am trying to upload an image to a directory and post its file path along with other data into a table. Upon submit it echos Error uploading file, but i cant figure out where its getting hung up. I believe it may have to do with my result variable but I'm not sure why. Thank you for your help.
<!-- Updated -->
<?PHP
error_reporting(E_ALL); ini_set('display_errors', 1);
$hostname = "localhost:3306";
$db_user = "root";
$db_password = "admin";
$database = "smlc";
$db_table = "program";
$db = mysqli_connect($hostname, $db_user, $db_password);
mysqli_select_db($db, $database);
$uploadDir=dirname(__FILE__)."/images/uploaded/programs/";
if(isset($_POST['Submit']))
{
$program_name = $_POST['program_name'];
$program_description = $_POST['program_description'];
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName,$filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$sql_program = "INSERT INTO program (program_name, program_description,filepath)
VALUES ('$program_name', '$program_description','$filePath')";
mysqli_query($sql_program) or die('Error, query failed ');
}
?>
<!--image_programs.php-->
<?PHP
$hostname = "localhost";
$db_user = "*";
$db_password = "*";
$database = "smlc";
$db_table = "program";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database);
$uploadDir = 'images/Uploaded/programs/';
if(isset($_POST['Submit']))
{
$program_name = $_POST['program_name'];
$program_description = $_POST['program_description'];
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName,$filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$sql_program = "INSERT INTO program (program_name, program_description,filepath)
VALUES ('$program_name', '$program_description','$filePath' )";
mysql_query($sql_program,$db) or die('Error, query failed ');
}
?>
<!-- Image Form -->
<form name="Image" enctype="multipart/form-data" action="image_programs.php" method="POST">
<tr>
<td>
<input type="File" name="Photo" size="2000000" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png" size="26"></td>
</tr>
<tr>
<td width="100">Program Name</td>
<td><input class="commentarea" name="program_name" type="text" id="program_name"></td>
</tr>
<tr>
<td width="100">Program Description</td>
<td><input class="commentarea" name="program_description" type="text" id="program_description"></td>
</tr>
<br/>
<tr>
<td>
<INPUT type="Submit" class="button" name="Submit" value="Submit">
</td>
</tr>
</form>
<?phptagerror_reporting(E_ALL); ini_set('display_errors', 1);see if it yields anything. Alsoor die(mysql_error())tomysql_query().mysql_select_db($database,$db);that will fix the 1st error.$uploadDir = 'images/Uploaded/programs/';and your error isUnable to move 'C:\xampp\tmp\php4A35.tmp' to '.../smlc/images/Uploaded/programs/pew.jpg'not the same folder. Plus, seems to have 3 dots in there.Uploadedis not the same asuploaded, should your folder be all in lowercase.