PHP机器不工作

PHP机器不工作,php,html,Php,Html,我试图发布表单隐藏输入类型中的随机值。。但它没有发布任何价值观。。 使用函数发布值 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript" src="jquery.form.js"></script> <scrip

我试图发布表单隐藏输入类型中的随机值。。但它没有发布任何价值观。。 使用函数发布值

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#images').on('change',function(){
        $('#multiple_upload_form').ajaxForm({
            target:'#images_preview',
            beforeSubmit:function(e){
                $('.uploading').show();
            },
            success:function(e){
                $('.uploading').hide();
            },
            error:function(e){
            }
        }).submit();
    });
});
</script>
<form method="post" name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
    <input type="hidden" name="randnum" id ="randnum" value="<?php echo mt_rand(1000,10000000); ?>" />
    <input type="hidden" name="image_form_submit" value="1"/>
        <label>Choose Image</label>
        <input type="file" name="images[]" id="images" multiple >
    <div class="uploading none">
        <label>&nbsp;</label>
        <img src="uploading.gif"/>
    </div>


</form>
每次发布表单时,我都会尝试存储一个随机数…

您需要响应mt_rand生成的值,如下所示:-

<input type="hidden" name="randnum" value="<?php echo mt_rand(1000,10000000); ?>" />
注意:-如果我更改了form.js库文件,您的代码和我的更改都可以正常工作:-

<script type="text/javascript" src="jquery.form.js"></script><!--local URL-->
致:-

您需要响应mt_rand生成的值,如下所示:-

<input type="hidden" name="randnum" value="<?php echo mt_rand(1000,10000000); ?>" />
注意:-如果我更改了form.js库文件,您的代码和我的更改都可以正常工作:-

<script type="text/javascript" src="jquery.form.js"></script><!--local URL-->
致:-

而不是

这将帮助您在每次提交要上载的文件时生成密钥 如果$\u POST['image\u form\u submit']=1

而不是

这将帮助您在每次提交要上载的文件时生成密钥 如果$\u POST['image\u form\u submit']=1


嘿,请使用echo打印值,例如。value=我已经上传了完整的代码…它正在发布其他图像信息…上传了它…它是.php,我添加了jquery lib..嘿,请使用echo打印值,例如。value=我已经上传了完整的代码…它正在发布其他图像信息…上传它…它是.php,我添加了jquery lib..我要发布表单中的值。。我知道如果我生成编号,它会起作用。提交后,我想发布表单中的值。。我知道如果我生成编号,它会起作用。提交后,显示没有错误。。。。只有随机数值未过帐。。。正在发布有关图像的所有其他详细信息。显示…时没有错误。。。。只有随机数值未过帐。。。有关这些图像的所有其他详细信息都已发布。
<input type="hidden" name="randnum" id ="randnum" 
         value="<?php echo mt_rand(1000,10000000); ?>" />
 $rand=mt_rand(1000,10000000);
{
$rand = mt_rand(1000,10000000);

$con=new PDO("mysql:host=localhost;dbname=newimg","root","");
$images_arr = array();
foreach($_FILES['images']['name'] as $key=>$val){
    $image_name = $_FILES['images']['name'][$key];
    $tmp_name   = $_FILES['images']['tmp_name'][$key];
    $size       = $_FILES['images']['size'][$key];
    $type       = $_FILES['images']['type'][$key];
    $error      = $_FILES['images']['error'][$key];

    $target_dir = "uploads/";
    $target_file = $target_dir.$_FILES['images']['name'][$key];
    if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$target_file)){
        $images_arr[] = $target_file;   
        $addnew=$con->prepare("INSERT INTO attempt010(link,name,size,type)VALUES('$rand','$image_name','$size','$type')");
        $addnew->execute();
    }
}
$fetch_imgid=$con->prepare("SELECT * FROM attempt010 where link='$rand'");
$fetch_imgid->setFetchMode(PDO:: FETCH_ASSOC);
$fetch_imgid->execute();
   Please use try this,
   Your ajax script is not working try this and check if  opening and closing {} having error



    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta charset="utf-8">
        <title>Bootstrap Starter</title>
        <meta name="generator" content="Bootply" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
        <!--[if lt IE 9]>
              <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <style type="text/css">
        /*CUSTOM CODE HERE*/
        </style>

    </head>

    <body>

       <form method="post" name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
        <input type="hidden" name="randnum" id ="randnum" value="<?php echo mt_rand(1000,10000000); ?>" />
        <input type="hidden" name="image_form_submit" value="1"/>
            <label>Choose Image</label>
            <input type="file" name="images[]" id="images" multiple >
        <div class="uploading none">
            <label>&nbsp;</label>
            <img src="uploading.gif"/>
        </div>

    </form>

        <script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
        <script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $('#images').on('change',function(){


            var formObj = $("#multiple_upload_form");
            var formURL = formObj.attr("action");
            var formData = new FormData(formObj[0]);


            $('.uploading').show();
            $.ajax({
                        url: formURL,
                        type: "POST",
                        data:  formData,
                        contentType: false,
                        cache: false,
                        processData:false,
                        success: function(data, textStatus, jqXHR)
                        {
                            console.log(data);
                          $('.uploading').hide();

                        }         
                 });


        });
    });
    </script>
    </body>
    </html>

    <?php

     if($_POST['image_form_submit'] == 1)

    {
        $rand = $_POST['randnum'];

        $con=new PDO("mysql:host=localhost;dbname=newimg","root","");
        $images_arr = array();
        foreach($_FILES['images']['name'] as $key=>$val){
            $image_name = $_FILES['images']['name'][$key];
            $tmp_name   = $_FILES['images']['tmp_name'][$key];
            $size       = $_FILES['images']['size'][$key];
            $type       = $_FILES['images']['type'][$key];
            $error      = $_FILES['images']['error'][$key];

            $target_dir = "uploads/";
            $target_file = $target_dir.$_FILES['images']['name'][$key];
            if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$target_file)){
                $images_arr[] = $target_file;   
                $addnew=$con->prepare("INSERT INTO attempt010(link,name,size,type)VALUES('$rand','$image_name','$size','$type')");
                $addnew->execute();
            }
        }
        $fetch_imgid=$con->prepare("SELECT * FROM attempt010 where link='$rand'");
        $fetch_imgid->setFetchMode(PDO:: FETCH_ASSOC);
        $fetch_imgid->execute();

       }


    ?>