简体   繁体   English

我想添加多文件上传并在表单中显示

[英]I want to add multi file upload and display in my form

I already have one single file upload input field in my form and it well. 我的表单中已经有一个单一的文件上传输入字段,效果很好。 but I want multiple file input too in it. 但我也想在其中输入多个文件。 I tried many ways to add input field of multiple file upload and display code in my form but it seems it is my mistake I am not able to do it. 我尝试了多种方法来添加多个文件上传的输入字段并在表单中显示代码,但似乎这是我的错误,我无法做到。

I have multiple file code but please if anybody can help me to integrate it into my form. 我有多个文件代码,但是如果有人可以帮助我将其集成到表单中,请提供帮助。 my add and edit form is same in one. 我的添加和编辑表单合而为一。 and please help me on how the uploaded multiple images could be display. 并请帮助我显示如何显示上传的多张图片。 I really don't understand like one input one row in table then how can multiple images could display? 我真的不明白像表中的一行输入那么怎么显示多张图像?

below is my code: 下面是我的代码:

  1. edit.php is my form edit.php是我的表格
  2. multiple.php and display.php files contains code. multiple.phpdisplay.php文件包含代码。

edit.php edit.php

 <!DOCTYPE html> <html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 --> <meta charset="utf-8"> <title>library</title> <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width"> <link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/> <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <link rel="stylesheet" href="css/style.css" media="screen"> <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]--> <link rel="stylesheet" href="css/style.responsive.css" media="all"> <script src="js/jquery.js"></script> <script src="js/script.js"></script> <script src="js/script.responsive.js"></script> <script type="text/javascript" language="JavaScript"> jQuery(document).ready(function() { jQuery(".form-message").fadeOut(10000); }); </script> <style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; } .ie7 .post .layout-cell {border:none !important; padding:0 !important; } .ie6 .post .layout-cell {border:none !important; padding:0 !important; } </style></head> <body> <div id="art-main"> <div id="art-header-bg" class="clearfix"> </div> <div id="art-hmenu-bg" class="art-bar art-nav clearfix"> </div> <div class="art-sheet clearfix"> <header class="art-header clearfix"> <div class="art-shapes"> <h1 class="art-headline" data-left="0.5%"> <a href="http://www.99demos.blogspot.com" target="_blank">library</a> </h1> <h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2> </div> <nav class="art-nav clearfix"> <div class="art-nav-inner"> <ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul> </div> </nav> </header> <div class="art-layout-wrapper clearfix"> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-content clearfix"><article class="art-post art-article"> <h2 class="art-postheader">customer form</h2> <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell layout-item-0" style="width: 100%" > <br> <?php ob_start(); include('include/connect.php'); if(isset($_GET['id'])) { $qry = "SELECT * FROM tbl_emp where id=".$_GET['id']; $result = mysql_query($qry,$conn); while($row = mysql_fetch_array($result)); { if($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $age = $_POST["age"]; $gender=$_POST['gender']; $martial = $_POST["martial"]; $contact = $_POST["contact"]; $email = $_POST["email"]; $location= $_POST["location"]; $category= $_POST["category"]; IF($_FILES['file']['name']!='') { $file='uploads/'.$row['image']; @unlink($file); $tmp_name = $_FILES["file"]["tmp_name"]; $namefile = $_FILES["file"]["name"]; $ext = end(explode(".", $namefile)); $image_name=time().".".$ext; $fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name); } else { $image_name=$row['image']; } $sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', category='".$category."', image='".$image_name."' where id=".$_GET['id']; mysql_query($sqlAdd); header("Location:add.php?id=".@$_GET['id']."&msg=success"); exit; } } } else { if($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $age = $_POST["age"]; $gender=$_POST['gender']; $martial = $_POST["martial"]; $contact = $_POST["contact"]; $email = $_POST["email"]; $location= $_POST["location"]; $category= $_POST["category"]; IF($_FILES['file']['name']!='') { $tmp_name = $_FILES["file"]["tmp_name"]; $namefile = $_FILES["file"]["name"]; $ext = end(explode(".", $namefile)); $image_name=time().".".$ext; $fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name); } $sqlAdd = mysql_query("insert into tbl_emp(name,age,gender,martial,contact,email,location,category,image) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$category','$image_name')"); header("Location:index.php?msg=success"); exit; } } ob_end_flush(); if(isset($_GET['msg'])) { ?> <div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div> <?php } ?> <form method="post" name="login" id="login" enctype="multipart/form-data"> <table class="table" width="100%"> <tr> <td width="10%">Customer Details</td> <td></td> </tr> <tr> <td width="10%">Full Name</td> <td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td> </tr> <tr> <td width="20%">Age</td> <td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td> </tr> <tr> <td>Gender</td> <td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> /> Male <input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> /> Female</td> </tr> <tr> <td width="10%">Martial Status</td> <td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td> </tr> <tr> <td width="20%">Contact Number</td> <td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td> </tr> <tr> <td width="10%">Email Address</td> <td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td> </tr> <tr> <td width="10%">Location</td> <td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td> </tr> <tr> <td width="10%">category</td> <td> <select name="category" id="category" value="<?php echo @$row['11'];?>"> <option <?php if ($category== '1' ) echo 'selected="selected'; ?> value="1">1</option> <option <?php if ($category== '2' ) echo 'selected="selected'; ?> value="2">2</option> <option <?php if ($category== '3' ) echo 'selected="selected'; ?> value="3">3</option> </select> </td> </tr> <tr> <td width="10%">Image</td> <td><input name="file" type="file" multiple="" ></td> </tr> <?php if(isset($row['image'])) { ?> <tr> <td>&nbsp;</td> <td><img src="uploads/<?php echo $row['image'];?> " height="50" width="50"></td> </tr> <?php } ?> <tr> <td>&nbsp;</td> <td> <input name="submit" value="Submit" type="submit" class="submit"> <input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'"> </td> </tr> </table> </form> <a href="http://dme-medical.com/library/search.php">Go back to list</a> </div> </div> </div> </div> </article></div> </div> </div> </div> </div> <footer class="art-footer clearfix"> <div class="art-footer-inner"> <p>Copyright © 2016. All Rights Reserved.</p> <p class="art-page-footer"> </p> </div> </footer> </div> </body></html> 

multiple.php multiple.php

<?php
if(isset($_POST['submit'])){
    if(count($_FILES['upload']['name']) > 0){
        //Loop through each file
        for($i=0; $i<count($_FILES['upload']['name']); $i++) {
          //Get the temp file path
            $tmpFilePath = $_FILES['upload']['tmp_name'][$i];

            //Make sure we have a filepath
            if($tmpFilePath != ""){

                //save the filename
                $shortname = $_FILES['upload']['name'][$i];

                //save the url and the file
                $filePath = "uploaded/" . date('d-m-Y-H-i-s').'-'.$_FILES['upload']['name'][$i];

                //Upload the file into the temp dir
                if(move_uploaded_file($tmpFilePath, $filePath)) {

                    $files[] = $shortname;
                    //insert into db 
                    //use $shortname for the filename
                    //use $filePath for the relative url to the file

                }
              }
        }
    }

    //show success message
    echo "<h1>Uploaded:</h1>";    
    if(is_array($files)){
        echo "<ul>";
        foreach($files as $file){
            echo "<li>$file</li>";
        }
        echo "</ul>";
    }
}
?>

<form action="" enctype="multipart/form-data" method="post">

    <div>
        <label for='upload'>Add Attachments:</label>
        <input id='upload' name="upload[]" type="file" multiple="multiple" />
    </div>

    <p><input type="submit" name="submit" value="Submit"></p>

</form>

display.php Display.php的

 <?php $files = glob("uploaded/*.*"); for ($i=1; $i<count($files); $i++) { $image = $files[$i]; print $image ."<br />"; echo '<img src="'.$image .'" alt="Random image" height="300px" width="300px"/>'."<br /><br />"; } ?> 

ok, here is edit.php , which should handle multiple files and will also be mindful of data that was not serialized before... 好的,这里是edit.php ,它应该处理多个文件,并且还要注意之前未序列化的数据...

<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 -->
    <meta charset="utf-8">
    <title>library</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
    <link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/>
    <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="css/style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="css/style.responsive.css" media="all">


    <script src="js/jquery.js"></script>
    <script src="js/script.js"></script>
    <script src="js/script.responsive.js"></script>
    <script type="text/javascript" language="JavaScript">
    jQuery(document).ready(function()
    {
      jQuery(".form-message").fadeOut(10000);
    });
    </script>

<style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px;  }
.ie7 .post .layout-cell {border:none !important; padding:0 !important; }
.ie6 .post .layout-cell {border:none !important; padding:0 !important; }

</style></head>
<body>
<div id="art-main">
    <div id="art-header-bg" class="clearfix">
            </div>
    <div id="art-hmenu-bg" class="art-bar art-nav clearfix">
    </div>
    <div class="art-sheet clearfix">
<header class="art-header clearfix">


    <div class="art-shapes">
<h1 class="art-headline" data-left="0.5%">
    <a  href="http://www.99demos.blogspot.com" target="_blank">library</a>
</h1>
<h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2>


            </div>

<nav class="art-nav clearfix">
    <div class="art-nav-inner">
    <ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul> 
        </div>
    </nav>


</header>
<div class="art-layout-wrapper clearfix">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                        <div class="art-layout-cell art-content clearfix"><article class="art-post art-article">
                                <h2 class="art-postheader">customer form</h2>

                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 100%" >
        <br>


<?php
ob_start(); 
include('include/connect.php'); 
if(isset($_GET['id']))
{
$qry = "SELECT * FROM tbl_emp where id=".$_GET['id'];
    $result = mysql_query($qry,$conn);
    while($row = mysql_fetch_array($result));
    {
        $row['image'] = @unserialize($row['image']);
        if(!is_array($row['image'])) $row['image'] = array($row['image']);
        if($_SERVER["REQUEST_METHOD"] == "POST")
        {
            //always always always always escape...
            $name = mysql_real_escape_string($_POST["name"]);
            $age = mysql_real_escape_string($_POST["age"]);
            $gender= mysql_real_escape_string($_POST['gender']);
            $martial = mysql_real_escape_string($_POST["martial"]);
            $contact = mysql_real_escape_string($_POST["contact"]);
            $email = mysql_real_escape_string($_POST["email"]);
            $location= mysql_real_escape_string($_POST["location"]);
            $category= mysql_real_escape_string($_POST["category"]);

            $files = array();
            if(count($_FILES['file']['name']) > 0){
                //Loop through each file
                foreach($_FILES['file']['error']  as $key => $error) {
                    if ($error == UPLOAD_ERR_OK) {
                        //Get the temp file path
                        $tmpFilePath = $_FILES['file']['tmp_name'][$i];

                        //Make sure we have a filepath
                        if($tmpFilePath != ""){

                            //save the filename
                            $shortname = date('d-m-Y-H-i-s').'-'.$_FILES['file']['name'][$i];

                            //save the url and the file
                            $filePath = "uploaded/" . $shortname;

                            //Upload the file into the temp dir
                            if(move_uploaded_file($tmpFilePath, $filePath)) {

                                $files[] = $shortname;
                                //insert into db 
                                //use $shortname for the filename
                                //use $filePath for the relative url to the file

                            }
                        }
                    }
                }
            }
            If(!empty($files)) {
                //get data ready for insertion
                $allFiles = mysql_real_escape_string(serialize($files));
                //remove old files
                if(!empty($row['image'])) foreach($row['image'] as $oldFile) {
                    if(file_exists('uploaded/'.$oldFile)) unlink('uploaded/'.$oldFile);
                }
            }
            else {
                if(!is_array($row['image'])) $row['image'] = array($row['image']);
                $allFiles = mysql_real_escape_string(serialize($row['image']));
            }

             $sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', category='".$category."', image='".$image_name."'  where id=".$_GET['id'];
             mysql_query($sqlAdd);
             header("Location:add.php?id=".(int) @$_GET['id']."&msg=success");
             exit;
        }
    }
}
else
{
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
        //always always always always escape...
        $name = mysql_real_escape_string($_POST["name"]);
        $age = mysql_real_escape_string($_POST["age"]);
        $gender= mysql_real_escape_string($_POST['gender']);
        $martial = mysql_real_escape_string($_POST["martial"]);
        $contact = mysql_real_escape_string($_POST["contact"]);
        $email = mysql_real_escape_string($_POST["email"]);
        $location= mysql_real_escape_string($_POST["location"]);
        $category= mysql_real_escape_string($_POST["category"]);    


        $files = array();
        if(count($_FILES['file']['name']) > 0){
            //Loop through each file
            foreach($_FILES['file']['error']  as $key => $error) {
                if ($error == UPLOAD_ERR_OK) {
                    //Get the temp file path
                    $tmpFilePath = $_FILES['file']['tmp_name'][$i];

                    //Make sure we have a filepath
                    if($tmpFilePath != ""){

                        //save the filename
                        $shortname = date('d-m-Y-H-i-s').'-'.$_FILES['file']['name'][$i];

                        //save the url and the file
                        $filePath = "uploaded/" . $shortname;

                        //Upload the file into the temp dir
                        if(move_uploaded_file($tmpFilePath, $filePath)) {

                            $files[] = $shortname;
                            //insert into db 
                            //use $shortname for the filename
                            //use $filePath for the relative url to the file

                        }
                    }
                }
            }
        }
        If(!empty($files)) {
            $allFiles = mysql_real_escape_string(serialize($files));
             $result = mysql_query("INSERT INTO `tbl_emp` (`name`,`age`,`gender`,`martial`,`contact`,`email`,`location`,`category`,`image`) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$category','$image_name')") ? "success":"failure";
            header("Location:index.php?msg=$result");
            exit;
        }
    }
}
    ob_end_flush();

    if(isset($_GET['msg']))
    {
    ?>
    <div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div>
    <?php   

    }
?>


<form  method="post" name="login" id="login" enctype="multipart/form-data">
 <table class="table" width="100%">
    <tr>
    <td width="10%">Customer Details</td>
    <td></td>
  </tr>
    <tr>
    <td width="10%">Full Name</td>
    <td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td>
  </tr>
 <tr>
    <td width="20%">Age</td>
    <td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td>
  </tr>
   <tr>
   <td>Gender</td>
 <td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> />
 Male
 <input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> />
 Female</td>
 </tr>
  <tr>
    <td width="10%">Martial Status</td>
    <td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td>
  </tr>
  <tr>
    <td width="20%">Contact Number</td>
    <td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td>
  </tr>
   <tr>
    <td width="10%">Email Address</td>
    <td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td>
  </tr>
  <tr>
    <td width="10%">Location</td>
    <td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td>
  </tr>

   <tr>
    <td width="10%">category</td>
    <td>
    <select name="category" id="category" value="<?php echo @$row['11'];?>">
    <option <?php if ($category== '1' ) echo 'selected="selected'; ?> value="1">1</option>
    <option <?php if ($category== '2' ) echo 'selected="selected'; ?> value="2">2</option>
    <option <?php if ($category== '3' ) echo 'selected="selected'; ?> value="3">3</option>
  </select>
    </td>
  </tr>

  <tr>
    <td width="10%">Image</td>
    <td><input name="file[]" type="file" multiple="" ></td>

  </tr>
   <?php
   if(!is_array($row['image'])) $row['image'] = array($row['image']);
   if(!empty($row['image']))
   {
   ?>
   <tr>
        <td>&nbsp;</td>
        <td>
            <?php foreach($image as $row['image']): ?>
                <img src="uploads/<?=$image;?> " height="50" width="50">
            <?php endforeach; ?>
        </td>
   </tr>
    <?php
    }
    ?>
  <tr>
    <td>&nbsp;</td>
    <td>
    <input name="submit" value="Submit" type="submit" class="submit">
    <input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'">
    </td>
  </tr>
</table>
</form> 
<a href="http://dme-medical.com/library/search.php">Go back to list</a>       
    </div>
    </div>
</div>
</div>
</article></div>
                    </div>
                </div>
            </div>
    </div>
<footer class="art-footer clearfix">
  <div class="art-footer-inner">
<p>Copyright © 2016. All Rights Reserved.</p>
    <p class="art-page-footer">

    </p>
  </div>
</footer>

</div>



</body></html>

 <!----------------New Code ----------------------> <!DOCTYPE html> <html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.0.0.58475 --> <meta charset="utf-8"> <title>library</title> <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width"> <link href='https://sites.google.com/site/99webdemos/favicon.png' rel='shortcut icon' type='image/x-icon'/> <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <link rel="stylesheet" href="css/style.css" media="screen"> <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]--> <link rel="stylesheet" href="css/style.responsive.css" media="all"> <script src="js/jquery.js"></script> <script src="js/script.js"></script> <script src="js/script.responsive.js"></script> <script type="text/javascript" language="JavaScript"> jQuery(document).ready(function() { jQuery(".form-message").fadeOut(10000); }); </script> <script language="javascript" type="text/javascript"> window.onload = function () { var fileUpload = document.getElementById("fileupload"); fileUpload.onchange = function () { if (typeof (FileReader) != "undefined") { var dvPreview = document.getElementById("dvPreview"); dvPreview.innerHTML = ""; var regex = /^([a-zA-Z0-9\\s_\\\\.\\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/; for (var i = 0; i < fileUpload.files.length; i++) { var file = fileUpload.files[i]; if (regex.test(file.name.toLowerCase())) { var reader = new FileReader(); reader.onload = function (e) { var img = document.createElement("IMG"); img.height = "100"; img.width = "100"; img.src = e.target.result; dvPreview.appendChild(img); } reader.readAsDataURL(file); } else { alert(file.name + " is not a valid image file."); dvPreview.innerHTML = ""; return false; } } } else { alert("This browser does not support HTML5 FileReader."); } } }; </script> <style>.art-content .art-postcontent-0 .layout-item-0 { padding-right: 10px;padding-left: 10px; } .ie7 .post .layout-cell {border:none !important; padding:0 !important; } .ie6 .post .layout-cell {border:none !important; padding:0 !important; } </style></head> <body> <div id="art-main"> <div id="art-header-bg" class="clearfix"> </div> <div id="art-hmenu-bg" class="art-bar art-nav clearfix"> </div> <div class="art-sheet clearfix"> <header class="art-header clearfix"> <div class="art-shapes"> <h1 class="art-headline" data-left="0.5%"> <a href="http://www.99demos.blogspot.com" target="_blank">library</a> </h1> <h2 class="art-slogan" data-left="87.05%"><a href="http://99demos.blogspot.in/2014/06/createreadupdate-delete-with-image.html"></a></h2> </div> <nav class="art-nav clearfix"> <div class="art-nav-inner"> <ul class="art-hmenu"><li><a href="index.php" class="active">Home</a></li></ul> </div> </nav> </header> <div class="art-layout-wrapper clearfix"> <div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell art-content clearfix"><article class="art-post art-article"> <h2 class="art-postheader">customer form</h2> <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout"> <div class="art-content-layout-row"> <div class="art-layout-cell layout-item-0" style="width: 100%" > <br> <?php ob_start(); include('include/connect.php'); if(isset($_GET['id'])) { $qry = "SELECT * FROM tbl_emp where id=".$_GET['id']; $result = mysql_query($qry); $row = mysql_fetch_array($result); if($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $age = $_POST["age"]; $gender=$_POST['gender']; $martial = $_POST["martial"]; $contact = $_POST["contact"]; $email = $_POST["email"]; $location= $_POST["location"]; $drname= $_POST["drname"]; $cname= $_POST["cname"]; $clocation= $_POST["clocation"]; $implants=implode(',',$_POST['implants']); $problem= $_POST["problem"]; $tgiven= $_POST["tgiven"]; $tdate= $_POST["tdate"]; IF($_FILES['file']['name']!='') { $file='uploads/'.$row['image']; @unlink($file); $tmp_name = $_FILES["file"]["tmp_name"]; $namefile = $_FILES["file"]["name"]; $ext = end(explode(".", $namefile)); $image_name=time().".".$ext; $fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name); } else { $image_name=$row['image']; } $sqlAdd ="update tbl_emp set name='".$name."', age='".$age."', gender='".$gender."', martial='".$martial."', contact='".$contact."', email='".$email."', location='".$location."', drname='".$drname."', cname='".$cname."', clocation='".$clocation."', implants='".$implants."', problem='".$problem."', tgiven='".$tgiven."', tdate='".$tdate."', image='".$image_name."' where id=".$_GET['id']; mysql_query($sqlAdd); header("Location:add.php?id=".@$_GET['id']."&msg=success"); exit; } } else { if($_SERVER["REQUEST_METHOD"] == "POST") { $name = $_POST["name"]; $age = $_POST["age"]; $gender=$_POST['gender']; $martial = $_POST["martial"]; $contact = $_POST["contact"]; $email = $_POST["email"]; $location= $_POST["location"]; $drname= $_POST["drname"]; $cname= $_POST["cname"]; $clocation= $_POST["clocation"]; $implants= $_POST["implants"]; $problem= $_POST["problem"]; $tgiven= $_POST["tgiven"]; $tdate= $_POST["tdate"]; IF($_FILES['file']['name']!='') { $tmp_name = $_FILES["file"]["tmp_name"]; $namefile = $_FILES["file"]["name"]; $ext = end(explode(".", $namefile)); $image_name=time().".".$ext; $fileUpload = move_uploaded_file($tmp_name,"uploads/".$image_name); } $sqlAdd = mysql_query("insert into tbl_emp(name,age,gender,martial,contact,email,location,drname,cname,clocation,implants,problem,tgiven,tdate,image) VALUES('$name','$age','$gender','$martial','$contact','$email','$location','$drname','$cname','$clocation','$implants','$problem','$tgiven','$tdate','$image_name')"); header("Location:index.php?msg=success"); exit; } } ob_end_flush(); if(isset($_GET['msg'])) { ?> <div style="color:red;padding-bottom:10px;" class="form-message" align="center"><b>Task completd successfully.</b></div> <?php } ?> <form method="post" name="login" id="login" enctype="multipart/form-data"> <table class="table" width="100%"> <tr> <td width="10%">Customer Details</td> <td></td> </tr> <tr> <td width="10%">Full Name</td> <td><input name="name" type="text" placeholder="Firstname Lastname" pattern="[A-Za-z-0-9]+\\s[A-Za-z-'0-9]+" required value="<?php echo @$row['name'];?>"></td> </tr> <tr> <td width="20%">Age</td> <td><input name="age" type="text" value="<?php echo @$row['2'];?>" ></td> </tr> <tr> <td>Gender</td> <td><input type="Radio" name="gender" value="male" <?php if ($gender=='male') { echo 'checked'; } ?> /> Male <input type="Radio" name="gender" value="female" <?php if ($gender=='female') { echo 'checked'; } ?> /> Female</td> </tr> <tr> <td width="10%">Martial Status</td> <td><input name="martial" type="text" value="<?php echo @$row['4'];?>" ></td> </tr> <tr> <td width="20%">Contact Number</td> <td><input name="contact" type="text" value="<?php echo @$row['5'];?>"></td> </tr> <tr> <td width="10%">Email Address</td> <td><input name="email" type="text" value="<?php echo @$row['6'];?>"></td> </tr> <tr> <td width="10%">Location</td> <td><input name="location" type="text" value="<?php echo @$row['7'];?>" ></td> </tr> <tr> <td width="10%">Treatment Details</td> <td></td> </tr> <tr> <td width="10%">Doctor Name</td> <td><input name="drname" type="text" value="<?php echo @$row['8'];?>" ></td> </tr> <tr> <td width="10%">Clinic Name</td> <td><input name="cname" type="text" value="<?php echo @$row['9'];?>" ></td> </tr> <tr> <td width="10%">Clinic Location & Branch</td> <td><input name="clocation" type="text" value="<?php echo @$row['10'];?>" ></td> </tr> <tr> <td width="10%">Implants</td> <td> <select name="implants" id="implants" value="<?php echo @$row['11'];?>"> <option <?php if ($implants== '1' ) echo 'selected="selected'; ?> value="1">1</option> <option <?php if ($implants== '2' ) echo 'selected="selected'; ?> value="2">2</option> <option <?php if ($implants== '3' ) echo 'selected="selected'; ?> value="3">3</option> </select> </td> </tr> <tr> <td width="10%">Problem</td> <td><input name="problem" type="text" value="<?php echo @$row['12'];?>" ></td> </tr> <tr> <td width="10%">Treatment Given</td> <td><input name="tgiven" type="text" value="<?php echo @$row['13'];?>" ></td> </tr> <tr> <td width="10%">Treatment Date</td> <td><input name="tdate" type="date" value="<?php echo @$row['14'];?>" ></td> </tr> <tr> <td>multifile <td> <input id="fileupload" type="file" multiple="multiple" /> <hr /> <b>Live Preview</b> <br /> <br /> <div id="dvPreview"> </div> </td> </tr> <tr> <td width="10%">X-Ray Image</td> <td><input name="file" type="file" multiple="" ></td> </tr> <?php if(isset($row['image'])) { ?> <tr> <td>&nbsp;</td> <td><img src="uploads/<?php echo $row['image'];?> " height="50" width="50"></td> </tr> <?php } ?> <tr> <td>&nbsp;</td> <td> <input name="submit" value="Submit" type="submit" class="submit"> <input name="submit" value="Cancel" type="button" class="submit" onClick="window.location='index.php'"> </td> </tr> </table> </form> </div> </div> </div> </div> </article></div> </div> </div> </div> </div> <footer class="art-footer clearfix"> <div class="art-footer-inner"> <p>Copyright © 2016. All Rights Reserved.</p> <p class="art-page-footer"> </p> </div> </footer> </div> </body></html> <!-------------End of new code-------------------> 

 <?php $files = glob("uploaded/*.*"); for ($i=1; $i<count($files); $i++) { $image = $files[$i]; print $image ."<br />"; echo '<img src="'.$image .'" alt="Random image" height="300px" width="300px"/>'."<br /><br />"; } ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想读出我的多重上传表单的文件名,我想将它包含在数据库中 - I want to read out the filenames of my multi upload form, and I want to include it in the database 我要上传文件 - I want to upload file my file 多文件格式上传 - multi file form upload 我想将下载链接生成器添加到“ mini ajax文件上传表单”脚本中 - i want to add a download link generator to the “mini ajax file upload form” script 我想从表单页面上载XML文件。 上传后,必须将xml文件的值放入我的数组中 - I want to upload a XML file from a form page. After the upload, the values of the xml file had to be put in my array 我想从一个表中选择名称并显示在我的页面中 - i want select name form one table and display in my page 我想将我的提交数据显示到输入表单中 - i want to display my submit data into input form 我想上传一个文件,并且当文件上传时,该文件的值必须放在我的数组中 - I want to upload a file and when the file upload, the values of the file has to be put in my array 我想通过表单的输入字段(文本区域)添加代码,然后将其显示在网页上 - i want to add code through the form's input field(textarea) and then want to display it on the webpage 使用Ajax上传多文件以及提交表单 - Multi file upload with ajax along with a form submit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM