0
我用补品(用于休息的PHP库)制作一个休息Web服务。REST Webservice HTTP_PUT参数
我使用根据CRUD和REST编辑一个元素。
所以我打电话给我的方法与图片和文件类型,并解析参数,并保存在我的服务器上的base64编码文件。
代码:
function put($request) {
$response = new Response($request);
$msg = new ErrorMessage();
$dbmodel = new DBModel();
$arr = array('Data' => null,'Message' =>null,'Code' => null);
try{
$split = explode ('&',$request->data);
$para = array();
foreach($split as $i) {
$names = explode('=',$i);
if(!isset($names[0]) or !isset($names[1]))
{
throw new Exception();
}
$para[$names[0]] = $names[1];
}
}
catch(Exception $e)
{
$arr['Code'] = 400;
$arr['Message'] = $msg->getMessage(400);
$response->body = json_encode($arr);
return $response;
}
if (isset($para['picture']) or isset($para['filetype']))
{
if (isset($para['picture']) and isset($para['filetype']))
{
if (!($para['filetype'] == 'jpg' || $para['filetype'] == 'png'))
{
$arr['Code'] = 688;
$arr['Message'] = $msg->getMessage(617);
$response->body = json_encode($arr);
return $response;
}
$bin = base64_decode($para['picture']);
if (strlen($bin) >524288)
{
$arr['Code'] = 617;
$arr['Message'] = $msg->getMessage(617);
$response->body = json_encode($arr);
return $response;
}
$uid = $dbmodel->getUid($sid);
if($uid<1)
{
$arr['Code'] = 699;
$arr['Message'] = $msg->getMessage(699);
$response->body = json_encode($arr);
return $response;
}
$file = fopen($_SERVER['DOCUMENT_ROOT']."/img/".$uid.".".$para['filetype'], 'wb');
fwrite($file, $bin);
fclose($file);
}
else
{
$arr['Code'] = 616;
$arr['Message'] = $msg->getMessage(616);
$response->body = json_encode($arr);
return $response;
}
}
$arr['Code'] = 200;
$arr['Message'] = $msg->getMessage(200);
$response->body = json_encode($arr);
return $response;
}
问题:保存的图片是不是像原来它不能显示图像
我用http://www.redio.info/werkzeuge/file2base64.html我的图片转换成的base64。我认为这个问题可能出现在我的代码开始处的解析中。
原文:13.872字节
新形象:14.313字节
是不是像原来的那样...怎么样? – 2012-02-01 20:47:27
我更新了我的任务 – user547995 2012-02-01 20:52:34
用hexeditor(甚至只是一个文本编辑器)查看这两个文件,并寻找明显的差异。 – 2012-02-01 20:55:06