开发者

Help me to create images and save them in folder through String passed in POST parameter

Hi Guys i am using following code to get the uploaded image

$imagedata= 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
               . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
               . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
               . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';

$imagedat开发者_开发知识库a= base64_decode($imagedata);

    if(($img = @imagecreatefromstring($imagedata)) !== FALSE) 
    {
               //$filedb is having path string
          if (move_uploaded_file($_FILES['imagedata']['tmp_name'], $filedb))
          { 
             echo 'success';
          }
          else
           {
                         echo 'error 1';
          }
    }
   else
   {
        echo 'error 2';
   }

I have checked that the image composed successfully but i am doing something wrong in passing parameters to $_FILE[ ? ][ ? ] as a result i am getting result as error 1 Please guide me


There is no connection between the image you created from a string, and something in $_FILES. $_FILES is only populated if files are uploaded as part of a form submitted to your script.

If you just want to save the image you created from the string, get rid of all the code after imagecreatefromstring and use imagejpeg, imagegif or imagepng to write the file.


Like this

if(($img = @imagecreatefromstring($imagedata)) !== FALSE) 
{
      if( imagepng($img, $filedb) )
      { 
         echo 'success';
      }
      else
      {
        echo 'error 1';
      }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜