I've been trying to teach myself PHP and thought i would set myself a task of creating a gallery, but i have gotten to a hiccup with the upload script;
The image gets uploaded to the Directory but it doesn't save the file path etc.. in the database.
The code may not be very good as I'm just starting out and have been using different resources to complete this but if you guys could have a look to see where i'm going wrong then that would be great
<?php
// Enable sessions
session_start();
// Connect to database
$objConn1 = new COM("ADODB.Connection");
$objConn1->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ds/gallery.mdb;Persist Security Info=False");
// Check Admin is Logged in
if(empty($_SESSION['loggedInUser']))
{
// Go to page
header("Location: login.php");
exit;
}
if(!empty($_GET) || !empty($_POST))
{
// Upload File
$success_File1 = false;
if(!empty($_FILES['File1']['name']))
{
if(is_uploaded_file($_FILES['File1']['tmp_name']))
{
$uploaddir = "D:\home\C253134\client.iflintinternet.com/image/";
// Set file name and upload path
$File1name = $_FILES['File1']['name'];
$uploadFile1 = $uploaddir.rawurlencode($File1name);
$uploadFile1 = erreplace("%..", "", $uploadFile1);
$uploadFile1 = str_replace("%", "", $uploadFile1);
$success_File1 = move_uploaded_file($_FILES['File1']['tmp_name'], $uploadFile1);
}
}
// Run query
$objConn1->Execute("INSERT INTO [Images]([Image_Name], [Image_Description], [Filename], [Path], [Display]) VALUES('".@$_POST['Name']."', '".@$_POST['Description']."', '".substr(strrchr($uploadFile1, "/"), 1)."', '".@$uploadFile1."', '".@$_POST['DropDown1']."')");
// Go to page
header("Location: admin.php");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upload Image</title>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
</head>
<body>
<h2 align="center">Upload Image
</h2>
<p align="center">
</p>
<form style="WIDTH: 100%" id="Form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF'].(@($_SERVER['QUERY_STRING'] > ' ') ? '?'.$_SERVER['QUERY_STRING'] : '') ?>">
<p align="left">
Image Name:
<input id="Name" name="Name">
<br>
Image Description:
<input id="Description" name="Description">
<br>
Display:
</p>
<select id="DropDown1" name="DropDown1">
<option selected="selected" value="Yes">Yes
<option value="No">No
</select>
<br>
<br>
<input id="File1" type="file" name="File1">
<br>
<input id="Submit1" value="Upload" type="submit" name="Submit1">
</form>
</body>
</html>
<?php
// Close database connection
if(isset($objConn1)) @$objConn1->Close();
?>
cheers,
Tommyflint

New Topic/Question
Reply




MultiQuote







|