Solved

Upload multiple images (pictures) using the php/html form

Posted on 2016-10-02
2
74 Views
Last Modified: 2016-10-02
Hi Experts:

I have this php html form to add data and upload a image (picture) to the database.  Datatype of the column storing the image is BLOB.  Currently, I can upload only 1 image (picture) per form submission.  Is it possible to upload more than 1 image (picture) using the form.

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type='text/javascript'><!--
function initFlyouts(){initPublishedFlyoutMenus([{"id":"122664640769900158","title":"Library Catalog","url":"index.html"},{"id":"532658225518218983","title":"About the Library","url":"http:\/\/icscborrowinglibrary.com\/aboutlibrary.html"},{"id":"813612181614597800","title":"Ask a Librarian","url":"ask-a-librarian.html"},{"id":"939506420111845331","title":"Support your Library","url":"support-your-library.html"}],'845325556776834118',"<li class='wsite-nav-more'><a href='#'>more...<\/a><\/li>",'',false)}
if (Prototype.Browser.IE) window.onload=initFlyouts; else document.observe('dom:loaded', initFlyouts);
//-->
</script>
</head>
<body class='wsite-theme-light wsite-page-add-books weeblypage-add-books'>
<div id="wrapper">
        <div id="container">
            <div id="header" class="wsite-header"></div>

            
            
            
            <div id="contenttop">
                <div id="contentbtm">
                    <div id="content">
                <div id='wsite-content' class='wsite-not-footer'>
<div class='wsite-not-footer'>
<div ><div id="698106845765048406" align="left" style="width: 100%; overflow-y: hidden;" class="wcustomhtml"><form enctype="multipart/form-data" action="add.php" method="POST">
<h3><font color='black'>Add Properties:</font></h3>
<br />
<table> 
<tr><td><font color='black'>Name:</font></td><td> <input type="text" name="name" size="40"></td></tr> 
<tr><td><font color='black'>Location:</font></td><td> <input type="text" name="location" size="40"></td></tr> 
<tr><td><font color='black'>Description:</font></td><td><textarea cols="31" rows="6" name="description"></textarea></td></tr> 
<tr><td><font color='black'>Area:</font></td><td> <input type="text" name="area" size="40"></td></tr>
<tr><td><font color='black'>Call #:</font></td><td> <input type="text" name="callnum" size="40"></td></tr> 
<tr><td><font color='black'>Property Type:</font></td><td> 
   <select name="type">
     <option value="Single Family Home">Single Family Home</option>
     <option value="Commercial">Commercial</option>    
     <option value="Condo">Condo</option>
     <option value="Apartment">Apartment</option>
   </select>
 </td></tr> 
<tr><td><font color='black'>Photo:</font></td><td> <input type="file" name="photo" size="40"></td></tr> 
<tr><td></td><td><input type="submit" value="Add"></td></tr></font>
</table></form><hr>
</div>



</div>

</div>
</div>

                    <div class="clear"></div>
                    </div>
                </div>        
            </div>
                <div id="footer" align='center'>
<a name="fb_share">Share us on Facebook</a> 
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
        type="text/javascript">
</script>&nbsp;&nbsp;
                    <A HREF="faqs.html"><u>FAQs</u></A>&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="recommend.html"><u>Recommend a purchase</u></A>&nbsp;&nbsp;
<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
                </div>
        <div class="clear"></div>        
        </div>            
    </div> 

</body>
</html>

<?php

// Connects to your Database 
$dbh=mysql_connect("jackrealestatecom.jillmysql.com", "jack", "Cher!f2015") or die(mysql_error()) ; 
mysql_select_db("properties") or die(mysql_error()) ; 
$maxsize = 10000000;


if($_POST) {
  //This is the directory where images will be saved 
  $target = "images/";
  $target = $target . basename( $_FILES['photo']['name']); 

  $photosize = $_FILES['photo']['size']; 
  if($photosize > $maxsize){
    echo "Sorry, file size exceeds the limit.<br><br>"; 
    exit();
   }

 
  //This gets all the other information from the form 
  $name=$_POST['name']; 
  $location=$_POST['location'];
  $callnum=$_POST['callnum'];
  $type=$_POST['type'];  
  $description=$_POST['description']; 
  $area=$_POST['area']; 
  $pic=$_FILES['photo']['name']; 
 
  //Writes the information to the database 
  mysql_query("INSERT INTO listings (id,name,location,description,callnum,type,area,image)  VALUES ('$id', '$name', '$location', '$description', '$callnum', '$type', '$area', '$pic')") ; 
 
  //Writes the photo to the server 
  if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { 
    //Tells you if its all ok 
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory<br><br>"; 
  } else { 
    //Gives and error if its not 
    echo "Sorry, there was a problem uploading your file.<br><br>"; 
  } 
}
// close the database connection
mysql_close($dbh)

?> 

Open in new window

0
Comment
Question by:imranasif17
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 500 total points
ID: 41825671
In HTML5 you can add a multiple attribute to allow you to select multiple files. The $_FILES array will have an additional dimension to carry the additional information. You can find more information here.
0
 

Author Closing Comment

by:imranasif17
ID: 41825683
Perfect.....
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CSS for <center> 14 35
Compiling PHP with Curl plus protocols 8 23
title attribute 5 26
write html in textarea and record it into a database table 3 10
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question