我正在尝试将 PHP 图像路径传递给 JavaScript,然后传递给外部 PHP 文件。
发件人.php
<script>
var imagepath = "<?php echo "'.$image_name .'"?>";
function loadXMLDoc3() { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("demo").innerHTML = this.responseText; } }; xhttp.open("POST", "loader.php?image=" + imagepath, true); xhttp.send(); }
</script>
<?php
//path to image files directory//
$all_files = glob("images/emojis/*.*");
for ($i=0; $i<count($all_files); $i++)
{
$image_name = $all_files[$i];
$supported_format = array('gif','jpg','jpeg','png');
$ext = strtolower(pathinfo($image_name, PATHINFO_EXTENSION));
if (in_array($ext, $supported_format))
{
//Display images from path directory//
echo '<div class="bottom"><div class="col"><a href="#"><img src="'.$image_name .'" onclick="loadXMLDoc3()"/></a></div>'." <?php ?>";
} else {
continue;
}
}
?>
接收器.php
<?php
if(isset($_GET['image']))
{
shell_exec("sudo led-image-viewer -C /var/www/html/led/".urldecode($_GET['image'])." --led-gpio-mapping=adafruit-hat --led-rows=64 --led-cols=64");
}
?>
代码执行正常,但我无法从 xhttp.open("POST", "loader.php?image=" + imagepath, true); 获取图像路径。xhttp.send(); 到receiver.php
手掌心
相关分类