imagecreatefromstring导致500内部服务器错误

时间:2014-03-11 11:05:19

标签: php

我有bitmao实例我将此实例转换为base64string并通过php函数将其发送到服务器。现在我正在解码此字符串并调用imagecreatefromstring,但此函数提供500内部服务器错误。我希望将此图像存储到文件中。

我的.net功能如下:

 Bitmap icon = new Bitmap("C:\\Users\\HP\\Desktop\\mun.ico");

            System.IO.MemoryStream stream = new System.IO.MemoryStream();
            icon.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] imageBytes = stream.ToArray();
            // Convert byte[] to Base64 String
            string base64String = Convert.ToBase64String(imageBytes);

            HttpWebRequest m_ObjRequest; //Request which needed to be sent to server
            HttpWebResponse m_ObjResponse; // Response which is sent back from the server to the client

            StreamReader reader = null; // making a stream reader to read the web pageand initialize it to null

            string m_Url = "http://192.168.1.30/muneem/erp/uploadIcon.php"+ "?bitmap=" + base64String; // the url of that web page

            string m_Response = "";
            m_ObjRequest = (HttpWebRequest)WebRequest.Create(m_Url); // creating the url and setting the values
            m_ObjRequest.Method = "GET";
            m_ObjRequest.ContentType = "application/json; charset=utf-8";
            //m_ObjRequest.ContentLength = 500;
            m_ObjRequest.KeepAlive = false;

            m_ObjResponse = (HttpWebResponse)m_ObjRequest.GetResponse(); // getting response from the server
            using (reader = new StreamReader(m_ObjResponse.GetResponseStream())) // using stream reader to read the web page
            {
                m_Response = reader.ReadToEnd();
                reader.Close(); // Close the StreamReader
            }

            m_ObjResponse.Close();
            m_ObjRequest = null;
            m_ObjResponse = null;

我处理这个编码位图字符串的PHP代码如下:

$位图= $ _ GET ['位图']; $ data = base64_decode($ bitmap);

$ im = imagecreatefromstring($ data); if($ im!== false){     标题('内容类型:image / png');     imagepng($ IM);     imagedestroy($ IM); } 其他{     echo'发生错误。&#39 ;; }

编码的位图字符串如下:

$位图=" Qk02BAAAAAAAADYAAAAoAAAAEAAAABAAAAABACAAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP / 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9qwA // asAP9L / 9V / S // B //尽快/ 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9qwA / 0V / 2 / 9L / 9V / S // B / 0V / 2 / 9L / 9V / S // b // asAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP9L / 9V / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 // 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP9L / 9V / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 / 9L / 9V / S // b // asAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2rAD / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 // 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP9L / 9V / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 // 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2rAD / S // b / 0V / 2 / 9L / 9V / S // b / 0V / 2 / 9L / 9V / 9qwA / wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP / 2rAD / S // B / 0V / 2 // 2rAD / 9qwA / wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPasAP / 2rAD / AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA =="

为什么我从string的imagecreate上得到这个错误?

1 个答案:

答案 0 :(得分:2)

imagecreatefromstring不支持BMP格式。允许的格式为:JPEG,PNG,GIF,WBMP和GD2。