Javascript 基于复选框检查更新所选图像

Javascript 基于复选框检查更新所选图像,javascript,php,mysql,Javascript,Php,Mysql,我需要上传选定的图像,但我没有任何想法使它。有人能帮我解决这个问题吗?包括下面的代码。谢谢你提前帮忙 Test.php <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <sc

我需要上传选定的图像,但我没有任何想法使它。有人能帮我解决这个问题吗?包括下面的代码。谢谢你提前帮忙

Test.php

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function myFunction1(isChecked2){
$('.chckbox1').change( function() {
    var isChecked2 = this.checked;
    if(isChecked2) {
        $(this).parents("tr:eq(0)").find(".product_img").prop("disabled",false); 
    } else {
        $(this).parents("tr:eq(0)").find(".product_img").prop("disabled",true);}
})};
</script>
</head>

<body>
<form method="post" action="UPDATE.php">
<div class="row">
<div class="col-xs-4">
<table id="simple-table" class="table table-striped table-bordered table-hover">
<thead>
   <tr>
   <th class="center">Select</th>
   <th class="center">Product Image</th>
   <th class="center">New Image</th>
   </tr>
</thead>
<tbody>
<?php 

//connect to database
$con = mysql_connect("localhost","root","");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
//select table from database
mysql_select_db("MBTR", $con);

$result = mysql_query("SELECT * from maray_product_img WHERE product_id='P100044'");

//query resutl
$countrow = 1;
//read result           
while($row = mysql_fetch_array($result))
{

    $img_id=$row['img_id'];
    $p_id = $row['product_id'];
    $product_img_name = $row['product_img_name'];
    $product_img = $row['product_img'];
    $product_img_path = $row['product_img_path'];
    //$product_quantity = $row['product_quantity'];
?>
     <tr>
     <td class="center" style="vertical-align:middle"> <input name="img_id[]" type="checkbox" id="check[]" class="chckbox1 ace" value="<?php echo $img_id;?>" onclick="myFunction1(this)"/><span class="lbl red"><input type="hidden" name="product_id[<?php echo $img_id;?>]" value="<?php echo $p_id;?>"></span><input type="hidden" name="product_img_name[<?php echo $img_id;?>]" value="<?php echo $product_img_name;?>"></td>
      <td class="center"><img src="<?php echo $row['product_img_path'];?>" width="60" height="60"></td>
      <td class="center" style="vertical-align:middle"><input type="file" name="product_img[<?php echo $img_id;?>]" id="product_img[]" class="product_img  form-control" disabled></td>

      </tr>
<?php           
    $countrow++;
    }
?>
   </tbody>
   </table>
    </div><!-- /.span -->
    </div><!-- /.row -->
    <button type="submit" name="submit">Update</button>
</form>
</body>
</html>
<?php
error_reporting(E_ALL & ~E_NOTICE);
include ("dbconfig.php");
require_once('auth.php');

$product_img_name=$_FILES["product_img"]["name"];

if((isset($_POST['img_id'])))
        {
            $rand = rand(5,987897899);

            foreach($_POST["img_id"] as $imgId)
            {
                //$product_img_name= $_POST['product_img_name'][$imgId];
                $tmpName = $_FILES['product_img_name']['tmp_name'][$imgId];

                $imagetmp=addslashes (file_get_contents($tmpName));

                $name=basename($_FILES['product_img_name']['name'][$imgId]);
                $t_name=$_FILES['product_img']['tmp_name'][$imgId];
                $dir='upload';
                $new_name= date('dmY')."_".$product_code."_".$rand."_".$name;
                if(move_uploaded_file($t_name,$dir."/".$new_name))
                {
                    $query = mysql_query("UPDATE maray_product_img set product_img_name='$imagename',
                    product_img_path='upload/$imagename', product_img='$imagetmp' where img_id='$imgId' LIMIT 1");
                    echo "<script>alert ('Successfull! Data has been changed.')</script>";
                    echo "<script>window.location = 'test.php'</script>";

                }
                else
                {
                    echo "<script>alert ('Failed to update. Please try again')</script>";
                }

            }

        }

?>

无标题文件
函数myFunction1(isChecked2){
$('.chckbox1').change(函数(){
var isChecked2=此项已检查;
如果(isChecked2){
$(this).parents(“tr:eq(0)”).find(“.product_img”).prop(“disabled”,false);
}否则{
$(this).parents(“tr:eq(0)”).find(“.product_img”).prop(“disabled”,true);}
})};
挑选
产品形象
新形象

您的
输入类型=文件在哪里?@supercolhandsomegelboy正在测试中。php@SuperCoolHandsomeGelBoy你能帮我吗(谢谢。。