php保存base64数据 if(isset($param['cover_pic']) && !empty($param['cover_pic'])) { if (preg_match('/^(data:s*image/(w+);base64,)/', $param['cover_pic'], $result)){ $file_path = '/upload/project/' . $param['id'] . date('YmdHis') . '.' . $result[2]; if (file_put_contents('.' . $file_path, base64_decode(str_replace($result[1], '', $param['cover_pic'])))){ $param['cover_pic'] = $file_path; } } } js闭包 var title = 'blog'; (function(title){ $.post(url, {}, function(data){ alert(title);//output single's blog, 我们期望的是输出 blog }) }(title)) title = "single's blog"; (function(title){ $.post(url, {}, function(data){ alert(title);//output single's blog }) }(title)) for(var i=0;i<3;i++) { ((function(i){ $.get('/?'+i, {}, function(data){ alert(i); // alert(1) alert(2) alert(3) }) }(i)) }