Hi,
i am having trouble trying to upload my .jpg file onto my server allong with it’s information about it e.g file description onto my db. The code bellow:
if(isset($_POST['action']) and $_POST['action'] == 'upload')
{
$description = mysqli_real_escape_string($link, $_POST['description']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$file = ($_FILES['photo']['name']);
$target = './images/';
$target .= basename($_FILES['photo']['name']);
// Checkk if a file was actually uploaded
if(!is_uploaded_file($_FILES['photo']['tmp_name']) )
{
echo $error = 'Error, there was no file uploaded';
print_r($_FILES['photo']['tmp_name']);
// include 'error.html.php';
exit();
}
if(file_exists($target))
{
$error = 'This file already exists on the server';
echo ($target);
include 'error.html.php';
exit();
}
if(move_uploaded_file($_FILES['photo']['tmp_name'],$target))
{
// Get information from the form
$uploaddesc = $_POST['description'];
$uploadcat = $_POST['category'];
$uploadname = $_FILES['photo']['name'];
//Prepare for user submitted for safe database insert
$uploaddesc = mysqli_real_escape_string($link, $uploaddesc);
$uploadcat = mysqli_real_escape_string($link, $uploadcat);
$uploadname = mysqli_real_escape_string($link, $uploadname);
include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
$sql = "INSERT INTO image_detail SET Filename = '$uploadname',
Category = '$uploadcat', Description = '$uploaddesc'";
if(!mysqli_query($link, $sql) )
{
$error = 'Database error storing file information';
include 'error.html.php';
exit();
}
else
{
$output = 'The file and information has been stored successfully';
include 'success.html.php';
}
}
else
{
die("Error moving file");
}
}
<form enctype="multipart/form-data" action=" " method="post">
<div>
<label for="description"> Description: </label> <input type="text" name="description" id="description" /> <br >
</div>
<div>
<label for="category"> Category </label>
<select name="category" id="category">
<option value="Cheng_Huang_Temple">Cheng Huang Temple </option>
<option value="Shanghai_Zoo">Shanghai Zoo </option>
</select> <br />
</div>
<div>
<label for="uploadimg"> Upload Photo: </label>
<input type="file" id="photo" name="photo"/> <br >
</div>
<div>
<input type="hidden" name="action" value="upload" />
<input type="submit" value="Upload" />
</div>
</form>
for some reason why i submit my file allong with it’s info, php seems to go nito my, $error = ‘Error, there was no file uploaded’; state and i don’t know why. I looked at the tmp_name to see i was writing it correctly, but it is correct.
Can somebody please tell me why it seems to go into my eeror state please.
Thx