【问题标题】:want to change the path of the saving images folder... how to do this想要更改保存图像文件夹的路径...怎么做
【发布时间】:2016-02-06 15:21:11
【问题描述】:

javascript函数调用html2画布元素来截图目标div

<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>

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);

 ?>

不知道如何为保存图像提供不同的文件夹路径

【问题讨论】:

  • 任何人请告诉我这些东西

标签: javascript php html html5-canvas html2canvas


【解决方案1】:

通常使用copy 函数将文件上传到文件夹。 根据您的代码,您可以执行类似的操作

$dir_to_save = "foldername"
if (!is_dir($dir_to_save)) {
  mkdir($dir_to_save);
}

$path = $dir_to_save."/".$name;
file_put_contents($path, $unencodedData);

注意:使用 ABSOLUTE_PATH 而不是相对路径

了解更多information

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多