Home  >  Article  >  Backend Development  >  javascript - Problem with HTML JS passing value to PHP.

javascript - Problem with HTML JS passing value to PHP.

WBOY
WBOYOriginal
2016-08-04 09:19:431145browse

Maybe my thinking is not good. What I need to do is to select multiple pictures, click to automatically package the zip, and then download.
ZIP already exists, but PHP doesn’t understand it, so I made a form on the front end to get multiple image addresses to PHP, and then PHP traversed and packaged them into ZIP.
PHP

<code>$imagee = $_GET['pic'];
    foreach ($imagee as $k => $v) {
     $image[]= array(
            'image_src'  =>$v,
            'image_name' => mt_rand(1, 1111) . '.jpg'
        );
    }
</code>

Originally I wanted to get the specified src through js
js

<code><script>
var images = document.getElementsByClassName("1");
var imageStr = "";
for(var i=0;i<images.length;i++){
   imageStr+=images[i].src+'/';
}

alert(imageStr);
</script>
</code>

I found that the output is a piece of data, and PHP doesn’t know how to write a loop
Can you help me? Get the image address of the specified class and pass it to the background phpzip for packaging

Reply content:

Maybe my thinking is not good. What I need to do is to select multiple pictures, click to automatically package the zip, and then download.

ZIP already exists, but PHP doesn’t understand it, so I made a form on the front end to get multiple image addresses to PHP, and then PHP traversed and packaged them into ZIP.
PHP

<code>$imagee = $_GET['pic'];
    foreach ($imagee as $k => $v) {
     $image[]= array(
            'image_src'  =>$v,
            'image_name' => mt_rand(1, 1111) . '.jpg'
        );
    }
</code>
Originally I wanted to get the specified src through js

js

<code><script>
var images = document.getElementsByClassName("1");
var imageStr = "";
for(var i=0;i<images.length;i++){
   imageStr+=images[i].src+'/';
}

alert(imageStr);
</script>
</code>
I found that the output is a piece of data, and PHP doesn’t know how to write a loop

Can you help me? Get the image address of the specified class and pass it to the background phpzip for packaging

<code>$imagee = $_GET['pic'];
    foreach ($imagee as $k => $v) {
     $image[]= array(
            'image_src'  =>$v,
            'image_name' => mt_rand(1, 1111) . '.jpg'
        );
    }
我看你这段代码感觉你上传的变量就是一个$_GET['pic'],所以你在前端很可能提交的是一张图片还不是一段图片吧。如果你要提交一组图片,可能参考下下面的方式:
1。<input type="file" name="pic[]" >
这样在后台$_GET['pic']得到的就是一个数组了,可以遍历了。
2。使用js把前台选中的图片地址,json化,然后赋值给<input type="file" name="pic" >再提交表单,或者直接js提交表单。</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP message matchingNext article:PHP message matching