- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的表单中已经有一个单一的文件上传输入字段,而且很好。但我也想要多个文件输入。我尝试了很多方法来添加多个文件上传的输入字段并在我的表单中显示代码,但似乎是我的错误我无法做到这一点。
我有多个文件代码,但如果有人可以帮助我将它集成到我的表单中,请帮忙。我的添加和编辑表单合二为一。请帮助我了解如何显示上传的多张图片。我真的不明白就像在表格中输入一行然后如何显示多个图像?
下面是我的代码:
edit.php
是我的表单multiple.php
和 display.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> </td>
<td><img src="uploads/<?php echo $row['image'];?> " height="50" width="50"></td>
</tr>
<?php
}
?>
<tr>
<td> </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>
多个.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>
显示.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 />";
}
?>
最佳答案
好的,这里是 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> </td>
<td>
<?php foreach($image as $row['image']): ?>
<img src="uploads/<?=$image;?> " height="50" width="50">
<?php endforeach; ?>
</td>
</tr>
<?php
}
?>
<tr>
<td> </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>
关于php - 我想在我的表单中添加多文件上传和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35594724/
我创建了一个用户可以添加测试的字段。这一切运行顺利我只希望当用户点击(添加另一个测试)然后上一个(添加另一个测试)删除并且这个显示在新字段中。 所有运行良好的唯一问题是点击(添加另一个字段)之前添加另
String[] option = {"Adlawan", "Angeles", "Arreza", "Benenoso", "Bermas", "Brebant
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在努力将 jQuery 滚动功能添加到 nav-tab (Bootstrap 3)。我希望用户能够选择他们想要的选项卡,并在选项卡内容中有一个可以平滑滚动到 anchor 的链接。这是我的代码,可
我正在尝试在用户登录后再添加 2 个 ui 选项卡。首先,我尝试做一个之后。 $('#slideshow').tabs('remove', '4'); $("#slideshow ul li:last
我有一个包含选择元素的表单,我想通过选择添加和删除其中一些元素。这是html代码(这里也有jsfiddle http://jsfiddle.net/txhajy2w/):
正在写这个: view.backgroundColor = UIColor.white.withAlphaComponent(0.9) 等同于: view.backgroundColor = UICo
好的,如果其中有任何信息,我想将这些列添加到一起。所以说我有 账户 1 2 3 . 有 4 个帐户空间,但只有 3 个帐户。我如何创建 java 脚本来添加它。 最佳答案 Live Example H
我想知道是否有一种有效的预制算法来确定一组数字的和/差是否可以等于不同的数字。示例: 5、8、10、2,使用 + 或 - 等于 9。5 - 8 = -3 + 10 = 7 + 2 = 9 如果有一个预
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我的 Oracle SQL 查询如下- Q1- select hca.account_number, hca.attribute3, SUM(rcl.extended_amou
我正在阅读 http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingG
我正在尝试添加一个“加载更多”按钮并限制下面的结果,这样投资组合页面中就不会同时加载 1000 个内容,如下所示:http://typesetdesign.com/portfolio/ 我对 PHP
我遇到这个问题,我添加了 8 个文本框,它工作正常,但是当我添加更多文本框(如 16 个文本框)时,它不会添加最后一个文本框。有人遇到过这个问题吗?提前致谢。 Live Link: JAVASCRIP
add/remove clone first row default not delete 添加/删除克隆第一行默认不删除&并获取正确的SrNo(例如:添加3行并在看到问题后删除SrNo.2)
我编码this ,但删除按钮不起作用。我在控制台中没有任何错误.. var counter = 0; var dataList = document.getElementById('materi
我有一个类似数组的对象: [1:数组[10]、2:数组[2]、3:数组[2]、4:数组[2]、5:数组[3]、6:数组[1]] 我正在尝试删除前两个元素,执行一些操作,然后将它们再次插入到同一位置。
使用的 Delphi 版本:2007 你好, 我有一个 Tecord 数组 TInfo = Record Name : String; Price : Integer; end; var Info
我使用了基本的 gridster 代码,然后我声明了通过按钮添加和删除小部件的函数它工作正常但是当我将调整大小功能添加到上面的代码中时,它都不起作用(我的意思是调整大小,添加和删除小部件) 我的js代
title 323 323 323 title 323 323 323 title 323 323 323 JS $(document).keydown(function(e){
我是一名优秀的程序员,十分优秀!