[英]How can I save a file on remote server with js and php?
我使用html2canvas.js保存圖像。 如果與php文件位於同一位置/服務器,我就知道如何使用它。
但是現在我想使用eBay列表模板中的腳本並將圖像保存到我的服務器。 這可能嗎?
這是我的php文件:
<?php
function ImageFillAlpha($image, $color) {
imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), $color);
}
function imageCreateCorners($sourceImageFile, $name, $radius) {
# test source image
if (file_exists($sourceImageFile)) {
$res = is_array($info = getimagesize($sourceImageFile));
}
else
$res = false;
# open image
if ($res) {
$w = $info[0];
$h = $info[1];
switch ($info['mime']) {
case 'image/jpeg': $src = imagecreatefromjpeg($sourceImageFile);
break;
case 'image/gif': $src = imagecreatefromgif($sourceImageFile);
break;
case 'image/png': $src = imagecreatefrompng($sourceImageFile);
break;
default:
$res = false;
}
}
# create corners
if ($res) {
$q = 10; #change this if you want
$radius *= $q;
$r = 0;
$g = 0;
$b = 0;
$nw = $w * $q;
$nh = $h * $q;
$img = imagecreatetruecolor($nw, $nh);
$alphacolor = imagecolorallocate($img, 0, 0, 0);
imagealphablending($img, false);
imagesavealpha($img, true);
imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor);
imagefill($img, 0, 0, $alphacolor);
imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h);
# resize image down
$dest = imagecreatetruecolor($w, $h);
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor);
imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh);
# output image
$res = $dest;
imagedestroy($src);
imagedestroy($img);
imagepng($res, 'cart/'.$name);
}
return $res;
}
$image = $_POST['plate_image'];
$ebay_user = $_POST['ebay_user'];
$decoded = base64_decode(str_replace('data:image/png;base64,', '', $image));
$date = date('m-d-Y', time());
$name = "evgrave-".$ebay_user."-".$date.".png";
file_put_contents("/var/www/html/SERVERLOCATION/img/" . $name, $decoded);
$full_path = "/var/www/html/SERVERLOCATION/img/" . $name;
imageCreateCorners($full_path, $name, 25);
$name1 = 'img/'.$name;
echo '<div class="download">';
echo '<br /><p>Result:</p><br />';
echo "<img src='$name1' alt='image' id='img' />";
echo '<p class="download-btn"><a id="download" class="left" href="download.php?&img=' . $name1 .'">Download Image</a><a id="send" class="right" href="#">Send Order</a></p>';
echo '</div>';
?>
這是js函數:
html2canvas($('#output'), {
"logging": true,
"onrendered": function(canvas){
var dataURL = canvas.toDataURL("image/png");
$.post('REMOTESERVER/image.php',{
plate_image: dataURL,
ebay_user: ebay_user
},function(data){
$('.overlay').remove();
$('#result').html(data);
});
}
});
有什么幫助嗎? 謝謝
您可以通過多種方式進行操作。 這是其中兩個(盡管它們的概念相同)。
這與方法1非常相似,但是使用不同的協議。 的FTP
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.