[英]Get slider value to PHP
I am trying to make an imagecompression tool in which I would like to define the compression rate with a slider. 我正在尝试制作一个图像压缩工具,在其中我想使用滑块定义压缩率。 The value of the slider is an input for the php-function imagejpeg and this is where I am stuck... 滑块的值是php函数imagejpeg的输入,这就是我遇到的问题...
I can't get the slider value into php... 我无法将滑块值转换为php ...
I am working with a HTML slider that I have created as followed: 我正在使用如下创建的HTML滑块:
<form action="" method="POST">
<input type="range" min="0" max="100" value="100" step="1" id="compressSlider" name="ratiovalue" oninput="ratioCalculate(value)" style="width:400px;">
<span id="volume">100</span>
</form>
And this is my Javascript and PHP -code: 这是我的Javascript和PHP代码:
<script>
function ratioCalculate(slider) {
var slideval = document.getElementById("volume");
var filesizekb = document.getElementById("Filesizekb");
var filesizepro = document.getElementById("Filesizepro");
<?php
$compressed_image = new handledImage();
$temp_image = imagecreatefromjpeg($_SESSION['targetfile']);
if(isset($_POST['compressSlider'])) {
imagejpeg($temp_image, 'uploads/compressedSliderImage.jpg', $_POST['compressSlider']);
$compressed_image->name = 'compressedSliderImage';
$compressed_image->type = 'jpg';
$compressed_image->size = filesize('uploads/compressedSliderImage.jpg');
$compressed_image->ratio = $_POST['compressSlider'];
$images[5] = $compressed_image;
}
else {
$compressed_image->ratio = -1;
}
?>
slideval.innerHTML = slider;
document.getElementById('compressed_shown').src = 'uploads/compressedSliderImage.jpg';
filesizekb.innerHTML = 'Filesize (kB): '+<?php // echo convert_unit($images[5]->size); ?>;
filesizepro.innerHTML = 'Filesize (%): '+<?php // echo calculate_percentage($images[5]->size, $images[0]->size); ?>;
}
</script>
Slider is the value of the slider in Javascript. 滑块是Javascript中滑块的值。 The Javascript variable changes when I use my slider, but the php varaible ($_POST['compressSlider']) doesn't... 当我使用滑块时,Javascript变量会更改,但是php变量($ _POST ['compressSlider'])不会...
Where is the submit button? 提交按钮在哪里? You cannot update serverside synchronously with client side. 您无法与客户端同步更新服务器端。 When do you reload the page and send the POST data? 什么时候重新加载页面并发送POST数据? I mean the data in the javascript function is set when loading the page. 我的意思是加载页面时设置了javascript函数中的数据。 Maybe an update button or apply? 也许是更新按钮或应用? And reload the page using $_POST? 并使用$ _POST重新加载页面?
And the name is wrong.. 这个名字是错误的..
<input type="range" min="0" max="100" value="100" step="1" id="compressSlider" name="ratiovalue" oninput="ratioCalculate(value)" style="width:400px;">
should be 应该
<input type="range" min="0" max="100" value="100" step="1" id="compressSlider" name="compressSlider" oninput="ratioCalculate(value)" style="width:400px;">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.