Below code uploads images one by one. I want to upload multiple images!
<?php
//config
require("./configuration.php");
$id = $_GET['id'];
$q = mysql_query("SELECT * FROM books WHERE id='$id'") or die(mysql_error());
$row = mysql_fetch_array($q);
$name = $row['name'];
echo '<div class="center-top"> NAME: <strong style="font-size:22px;">'.$name.'</strong> </div>';
//begin upload
if(isset($_POST['submit']))
{
$title = htmlspecialchars($_POST['title'],ENT_QUOTES);
$path = "./upload/images/";
$name_pic = $_FILES['file']['name'];
$ext = strtolower(substr(strrchr($name_pic, "."), 1));
$allow = array("jpg", "jpeg", "JPG", "JPEG", "png", "gif");
$uptype = ($_FILES['file']['tmp_name']);
if (in_array($ext, $allow))
{
//md5 hash for random image name
$rand = rand(0,10000);
$md5 = md5($rand);
$new_file_name = "{$md5}.{$ext}";
$move_file = move_uploaded_file($_FILES['file']['tmp_name'], $path.$new_file_name);
if($move_file) {
mysql_query("INSERT INTO images (id, link, title, bid)
VALUES (NULL, '$new_file_name', '$title', '$id')") or die (mysql_error());
echo "<div class='yes'>succesfully added!</div>";
}}}
echo '
//form uploads
<form method="post" action="images.php?id='.$id.'" enctype="multipart/form-data">
<br />title: <br /><input type="text" name="title" value="'.$name.'"/><br />
<br /><br/><input name="file" type="file" />
<br /><input type="submit" name="submit" value="UPLOAD" /><br /><br />
</form>
//end form
';
?>
With this code delete an image:
<?php
$id = $_GET['id'];
$result = mysql_query("DELETE FROM images WHERE `id`='$id'");
echo "<div class='yes'>successfully deleted picture!</div>";
?>