简体   繁体   English

通过表单发布图像数组

[英]posting an array of images via a form

I have an array of dynamically created divs with images inside each and want to post the images via a form. 我有一个动态创建的div数组,每个div中都有图像,并且想要通过表单发布图像。

currently I am getting nothing alerted 目前我什么也没收到

added a var_dump($_POST) and got this result 添加了一个var_dump($ _ POST)并得到了这个结果

 array(3) { 
   ["imagename"]=> array(1) 
         { 
        [5]=> string(35) "upload_pic/thumbnail_1365064772.jpg" 
         } 
       ["id"]=> array(1)
         { 
        [5]=> string(1) "5" 
         } 
       ["box_type"]=> array(1) 
         { 
        [5]=> string(5) "image" 
         } 
       }

how do I put that into a for loop? 如何将其放入for循环中?

Any help would be appreciated. 任何帮助,将不胜感激。

heres my code: 这是我的代码:

javascript: javascript:

function NewImgBox(imge, id)
        {
            id=id+i;
        var new1div = document.createElement('div');
        new1div.setAttribute('id', id);
        new1div.setAttribute('class', 'dragbox');
        new1div.setAttribute('iterate',i);
        new1div.style.position = "relative";
        new1div.style.top = p;
        new1div.style.left = p;
        new1div.style.cursor='move';
         new1div.innerHTML = "</div><br><input type='image' value='"+i+"' disabled name='image["+i +"]' src='"+imge+"' id='"+i+"'class='image1' style='width:300px; height:300px;'>";
        new1div.innerHTML=new1div.innerHTML+"<br><input type='hidden' value='"+imge+"' name='imagename["+i+"]'>"; 
        new1div.innerHTML=new1div.innerHTML+"<br><input type='hidden' value='"+i+"' name='id["+i+"]'><br><input name='box_type["+i+"]' type='hidden' value='image'/>";          
        document.getElementById("frmMain").appendChild(new1div);

        }

html: 的HTML:

<form id="frmMain" name="frmMain" enctype="multipart/form-data" action="dynamic_div6.php" method="post">    
   <input id="btn2" type="button" value="Add New Image" onClick="popitup('upload_crop.php');"/>
   <input type="submit" value="Save Page"  >

   <div id="content"> 
    <?
     if($new_image!='')
    {
    ?><script>NewImgBox('<? echo $new_image; ?>','draggable')</script><?    
     $new_image=''; 
    }
    ?> 
   </div>
</form>   

php: 的PHP:

 if($_SERVER['REQUEST_METHOD'] == "POST")  
  {
    foreach($_POST['image'] as $j => $value)
    {

        $imagename=$_POST["imagename"][$j];
        $box_type=$_POST['box_type'][$j];
        $box_id=$_POST['id'][$j];

        ?><script>alert("imagename=<? echo $imagename; ?>");</script><?
        ?><script>alert("box_id=<? echo $box_id; ?>");</script><?
        ?><script>alert("box_type=<? echo $box_type; ?>");</script><?
    }   
  } 

realised that the for loop should be 意识到for循环应该是

   foreach($_POST['imagename'] as $j => $value)

and it now works 现在可以了

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM