input_gallery.php
<?php
include('../includes/koneksi.php');
$post_id = isset($_POST['post_id']) ? $_POST['post_id'] : '';
$confirmation = isset($_POST['confirmation']) ? $_POST['confirmation'] : '';
$kategori = isset($_POST['kategori']) ? $_POST['kategori'] : '';
$post_image = isset($_POST['post_image']) ? $_POST['post_image'] : '';
$page = isset($_POST['page']) ? $_POST['page'] : '';
//Load image
if (!empty($_GET['post_id'])){
$result = mysql_query("SELECT * FROM static_page WHERE post_id =".$_GET['post_id']) or die(mysql_error());
$data = mysql_fetch_array($result);
$post_id = $data['post_ID'];
$page = $data['page'];
$post_image = $data['post_image'];
}
else {
echo "unable to select data";
echo "id is empty";
}
//Update Image
if (isset($_POST['update'])){
if (empty($_POST['post_id']))
{
$sqlstr = "INSERT INTO static_page(page, post_image) VALUES('".$page."','".$post_image."')";
}
else
{
$sqlstr = "UPDATE static_page SET page='".$page."', post_image='".$post_image."' WHERE id=".$_POST['post_id'];
}
$result = mysql_query($sqlstr) or die(mysql_error());
// cek type file & simpan file pada folder
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$exts = explode('.', $_FILES["image"]["name"]);
$upload_exts = end($exts);
//$upload_exts = end(explode(".", $_FILES["image"]["name"]));
if ((($_FILES["image"]["type"] == "image/gif")
|| ($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/png")
|| ($_FILES["image"]["type"] == "image/pjpeg"))
&& ($_FILES["image"]["size"] < 2000000)
&& in_array($upload_exts, $file_exts))
{
if ($_FILES["image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["image"]["name"] . "<br>";
echo "Type: " . $_FILES["image"]["type"] . "<br>";
echo "Size: " . ($_FILES["image"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["image"]["tmp_name"] . "<br>";
// Enter your path to upload file here
if (file_exists("c:\xampp\xampp\htdocs\rustoleum/photocms/" .
$_FILES["image"]["name"]))
{
echo "<div class='error'>"."(".$_FILES["image"]["name"].")".
" already exists. "."</div>";
}
else
{
move_uploaded_file($_FILES["image"]["tmp_name"],
"c:\xampp\xampp\htdocs\rustoleum/photocms/" . $_FILES["image"]["name"]);
echo "<div class='sucess'>"."Stored in: " .
"c:\xampp\xampp\htdocs\rustoleum/photocms/" . $_FILES["image"]["name"]."</div>";
}
}
}
else
{
echo "<div class='error'>Invalid file</div>";
}
//Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
//if (empty($_REQUEST['id'])) kirimEmail($idKategori, $judul, $news);
$confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";
}
?>
<div align="center">
<div style="width:800px;text-align:left;">
<?php echo $confirmation;?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<table>
<tr>
<td>Page <font color="red"></font></td>
<td><input type="text" size="50px" name="page" value="<?php echo $page; ?>" ></td>
</tr>
<tr>
<td>Featured Image </td>
<td>Image</td>
</tr>
<tr>
<td><input size="30px" type="file" name="image" value="<?php echo $image; ?>"/></td>
</tr>
<tr>
<td><br><br><input type="submit" name="update" value="Update"/><input type="reset" name="reset" value="Reset"/></td>
</tr>
</table>
</form>
</div>
</div>
</div>
If I try to upload picture file this message appears:
unable to select dataid is empty
Invalid file
Data telah tersimpan. (Data is saved)
Then in database, I have :
id image path judul
0 sulawesi.jpg
Yet, the picture is not yet moved to rustoleum/photocms/ as it suppose to. How to fix it?