Javascript 要更改“保存图像”文件夹的路径。。。如何做到这一点
javascript函数调用html2 canvas元素,以scrrenshot目标divJavascript 要更改“保存图像”文件夹的路径。。。如何做到这一点,javascript,php,html,html5-canvas,html2canvas,Javascript,Php,Html,Html5 Canvas,Html2canvas,javascript函数调用html2 canvas元素,以scrrenshot目标div <script type="text/javascript"> function capture() { $('#target').html2canvas({ onrendered: function (canvas) { //Set hidden field's value to image data (base-64 string)
<script type="text/javascript">
function capture() {
$('#target').html2canvas({
onrendered: function (canvas) {
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}
</script>
函数捕获(){
$(“#目标”).html2canvas({
onrendered:函数(画布){
//将隐藏字段的值设置为图像数据(base-64字符串)
$('img_val').val(canvas.toDataURL(“image/png”);
//手动提交表单
document.getElementById(“myForm”).submit();
}
});
}
php代码
<?php
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
//echo $unencodedData;
//Save the image
$date = date_create();
$timestamp= date_timestamp_get($date);
echo $timestamp;
$rand = mt_rand(100000,999999);
echo $rand;
$string = "cp-string";
echo $string;
$name = "$string.$timestamp.$rand.png";
//$name = "$string/$timestamp/$rand.png";
//$unencodedData = "$string/$timestamp/$rand";
file_put_contents($name , $unencodedData);
?>
不知道如何为保存图像指定不同的文件夹路径通常使用此功能将文件上载到文件夹中。
根据您的代码,您可以执行以下操作
$dir_to_save = "foldername"
if (!is_dir($dir_to_save)) {
mkdir($dir_to_save);
}
$path = $dir_to_save."/".$name;
file_put_contents($path, $unencodedData);
注意:使用绝对路径而不是相对路径
如需了解更多信息,请使用此功能将文件上载到文件夹中。
根据您的代码,您可以执行以下操作
$dir_to_save = "foldername"
if (!is_dir($dir_to_save)) {
mkdir($dir_to_save);
}
$path = $dir_to_save."/".$name;
file_put_contents($path, $unencodedData);
注意:使用绝对路径而不是相对路径
更多信息有人请告诉我这件事吗有人请告诉我这件事吗