所以我在php中有以下代码,您可以在其中从硬盘中选择一个文件,然后将其上传到facebook:
<?php
// calculations for the variables used here are above, but not necessary
$graph_url= "https://graph.facebook.com/me/photos?"
. "access_token=" .$access_token;
echo '<html><body>';
echo '<form enctype="multipart/form-data" action="'
.$graph_url .' "method="POST">';
echo 'Please choose a photo: ';
echo '<input name="source" type="file"><br/><br/>';
echo 'Say something about this photo: ';
echo '<input name="message"
type="text" value=""><br/><br/>';
echo '<input type="submit" value="Upload"/><br/>';
echo '</form>';
echo '</body></html>';
?>
然后我写了一个javascript函数做同样的事情:
function PHPPhotoUpload()
{
GraphURL= "https://graph.facebook.com/me/photos?" +"access_token=" + USERTOKEN;
document.getElementById("photoupload").innerHTML += '<p> ' + GraphURL + '</p>';
document.getElementById("photoupload").innerHTML += '<html><body>';
document.getElementById("photoupload").innerHTML += '<form enctype="multipart/form-data" action="' + GraphURL +'" method="POST">';
alert('<form enctype="multipart/form-data" action="' + GraphURL +' "method="POST">');
document.getElementById("photoupload").innerHTML += 'Please choose a photo: ';
document.getElementById("photoupload").innerHTML += '<input name="source" type="file"><br/><br/>';
document.getElementById("photoupload").innerHTML += 'Say something about this photo: ';
document.getElementById("photoupload").innerHTML += '<input name="message" type="text" value=""><br/><br/>';
document.getElementById("photoupload").innerHTML += '<input type="submit" value="Upload"/><br/>';
document.getElementById("photoupload").innerHTML += '</form>';
document.getElementById("photoupload").innerHTML += '</body></html>';
}
然而,当我点击 php 文件的上传按钮而不上传任何内容时,它给了我一个错误。当我在 javascript 中执行此操作时,该按钮根本不执行任何操作。当我选择了一张图片时也是如此。两者似乎都在我的文档中打印完全相同的 HTML 代码,那么为什么这不起作用?