Base 64 编码图像。上传推特头像
我正在尝试为 Twitter 制作一个图像上传表单来更改头像。 Twitter 说在我上传图片之前必须对其进行 Base 64 编码。这是一个示例
https://dev.twitter.com/docs/api /1/post/account/update_profile_image
我该怎么做到目前为止我一直收到错误
PHP 代码:
<?php // process form data
if ($_POST['image']){
// post profile update
$post_data = array(
"image" => $_POST['image']
);
$post_data = base64_encode($post_data);
echo $post_data;
}
else{
echo
" <form action='post.php' method='POST' enctype='multipart/form-data'>
<br><input type='hidden' name='image' value='update_profile_image'>
<input type='file' name='image' size='30'/><br>
<input type='submit' value='Upload' class='button'/>
</form>";}
?>
请帮忙
I'm trying to make an image upload form for twitter to change avatar. Twitter says the image has to be base 64 encoded before I upload it. So here's a sample
https://dev.twitter.com/docs/api/1/post/account/update_profile_image
How can I do this so far I've been getting errors
PHP Code:
<?php // process form data
if ($_POST['image']){
// post profile update
$post_data = array(
"image" => $_POST['image']
);
$post_data = base64_encode($post_data);
echo $post_data;
}
else{
echo
" <form action='post.php' method='POST' enctype='multipart/form-data'>
<br><input type='hidden' name='image' value='update_profile_image'>
<input type='file' name='image' size='30'/><br>
<input type='submit' value='Upload' class='button'/>
</form>";}
?>
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从表面上看,您根本没有从 POST 中检索图像。图像本身将在
$_FILES
中提供From the looks of this, you aren't retrieving the image from the POST at all. The image itself will be available in
$_FILES
这应该可以做到。
将上传的文件移动到某个目录,因为通过加密[tmp_name]无法得到所需的结果
This should do it.
Move the uploaded file to a directory because you cannot get required results by encrypting the [tmp_name]