如何使用请求中发布的名称保存图像


how to save the image with name posted in the request

我有一个简单的php文件,可以从我的安卓应用程序中读取图像:

<?php
$base=$_REQUEST['image'];
$cod=$_REQUEST['cod_anagrafico'];
echo $base;
// base64 encoded utf-8 string
$binary=base64_decode($base);
//binary, utf-8 bytes
header('Content-Type: bitmap; charset=utf-8');
print($binary);
$theFile = base64_decode($image_data);
$file = fopen('docs/test2.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo '<img src=docs/test.jpg>';
?>

但它用标准名称"测试"保存我的照片。所以我需要用变量"cod"的名称保存这个图像。我该怎么做?该过程结束时如何删除图像?

谢谢

更改此行,您应该没问题

$file = fopen("docs/{$cod}", 'wb');