脚本宝典收集整理的这篇文章主要介绍了PHP:从base64字符串中获取图像并将其存储在路径中,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
public function addNewCategory($category_tITle,$strImage) { // get the image From the base64 string. $strImage = base64_decode($strImage); $image = imagecreatefromstring($strImage); if($image !== false) { header('Content-tyPE: image/png'); imagepng($image); imagedestroy($image); } // set the path name of where the image is to be Stored. $path = $_SERVER['SERVER_NAME']."/uploads/".$category_title.".png"; // save the image in the path. file_put_contents($path,$image); // insert category and the image path into the MysqL database. $result = MysqLi_query($this->db->connect(),"INSERT INTO category(category_title,path,created_at) VALUES ('$category_title','$path',Now())"); if ($result) { return MysqLi_fetch_array($result); } else { return false; } }
使用该函数,路径变量存储在数据库中,但图像实际上并未存储在路径中.上面的代码有什么问题?
编辑
我将路径名更改为$path = $_SERVER [‘SERVER_NAME’].“/ MyPRoject / uploads /\”.$category_title.”.png“;.现在数据库中的路径值证明是我所期望的,但似乎图像本身并没有实际放入路径中.
//__DIR__ - path to your current script folder $server_path = __DIR__."/uploads/".$category_title.".png"; // save the image in the server path. file_put_contents($server_path,$image); //Web path to your image $web_path = $_SERVER['SERVER_NAME']."/uploads/".$category_title.".png"; //Write to DB web path of the image $result = MysqLi_query($this->db->connect(),'$web_path',Now())");
以上是脚本宝典为你收集整理的PHP:从base64字符串中获取图像并将其存储在路径中全部内容,希望文章能够帮你解决PHP:从base64字符串中获取图像并将其存储在路径中所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。