【发布时间】:2016-03-09 00:29:01
【问题描述】:
我正在通过 PHP 文件从 Android 应用程序向服务器发送 base64 字符串。
我从一个教程视频中得到了这个:
<?php
require 'Init.php';
header('Content-type : bitmap; charset=utf8');
if(isset($_POST['encoded_string'])){
$encoded_string = $_POST['encoded_string'];
$image_name = $_POST['image_name'];
$decoded_string = base64_decode($encoded_string);
$path = 'ProfileIcons/' .$image_name;
$file = fopen($path, 'wb');
$is_written = fwrite($file, $decoded_string);
fclose($file);
}
?>
它在目录中存储图像,但是当您打开时,它没有图像。这是一个空白的png。代码有问题吗?如果是这样,我应该使用什么?谢谢。
【问题讨论】:
-
你能贴出-$encoded_string返回的字符串格式吗?检查是否需要对其进行操作
-
您是从哪个教程中获得的?从安全的角度来看,这是一场灾难……几乎任何人都可以将他们想要的任何内容写入您的服务器磁盘。此外,通常没有理由使用 base64...您增加了 33% 的开销并浪费了内存。
标签: php android sql-server base64