您好我可以轻松上传php中的图片,如下代码
@$file_path = "admin/alumni_image/";
@$file_name= basename($_FILES['photo']['name']);
@$file_path = $file_path . basename( $_FILES['photo']['name']);
if(move_uploaded_file(@$_FILES['photo']['tmp_name'], $file_path))
{
$response1=array();
$query = "update alumni set photo = '".$file_name."' where alumni_id = '".$data['alumni_id']."'";
$query_run= mysql_query($query);
echo mysql_error();
}
但是当我把图像作为base64时,我现在面临着问题。
答案 0 :(得分:2)
最近我建造了类似的东西:
define("UPLOAD_DIR", "images/signatures/");
$signature = $_POST['signature']; // THIS IS YOUR BASE64 ENCODED STRING
$signature = str_replace('data:image/png;base64,', '', $signature);
$signature = str_replace(' ', '+', $signature);
$data = base64_decode($signature);
$file = UPLOAD_DIR . md5(microtime()) . '.png';
$success = file_put_contents($file, $data);