0
我想從我的javascript調用php文件,但它不起作用。沒有錯誤,但它沒有按預期工作。以下是我的代碼。無法從Javascript調用php文件
的Javascript
function getImage() {
obj = document.getElementById('paste-image');
postTo = "http://clipboard.netau.net/Web/shoot.php";
image = obj.getClipboardImageURL(postTo);
if (image) {
url = "shots/" + image;
document.getElementById("target").src = url;
document.getElementById("url").value = document.getElementById("target").src; // to get full path, hack, I know ;)
document.getElementById("container").style.display = "";
}
}
shoot.php
<?php
$filename = uniqid() . '.jpg';
$result = file_put_contents("./shots/" . $filename, file_get_contents('php://input'));
if (!$result) {
print "error";
exit();
}
echo $filename;
?>
我上傳的免費託管的代碼。 clipboard.netau.net
'#target'是一個'img'標籤嗎?如果是這樣,你爲什麼將shoot.php分配給它? – tjameson
沒有getClipboardImageURL這樣的方法。你從哪裏得到這個信息?它看起來像你剛剛從http://pastebin.com/gJmeFGvK複製它 – Barmar
我從http://lassebunk.dk/2009/07/19/using-the-clipboard-to-post-images/ –