douxunnian0423 2011-05-18 17:24
浏览 48
已采纳

将图像另存为blob类型

I have used MySQL to save a image as a blob type. I 'm uploading files through PHP and when I get the image back I revive only a part of it. How can I improve the max size ? (my image file size is less than 300 KB)

PHP uploader...

if($_FILES!=null && $_POST!=null){
    $file = $_FILES["image"]["tmp_name"];   

    if(!isset($file)){
        echo "Please upload an image";
    }else{
        $image = addslashes(file_get_contents($_FILES['image']['tmp_name']));

        $image_name = addslashes($_FILES['image']['name']);
        $type=$_POST['type'];

        $image_size = getimagesize($_FILES['image']['tmp_name']);

        if($image_size==FALSE)
            echo "That's not an image.";
        else
        {

            if(!(mysql_query("INSERT INTO store (name,image,type) values  ('$image_name','$image','$type')")))
                echo "Problem uploading image";
            else
            {
                $lastid = mysql_insert_id();
                echo "Image uploaded. <p /> Your image: <p /> <img id='imageId' src=get.php?id=$lastid>";
            }
        }
    }
  }

retrieving image

$id = addslashes($_REQUEST['id']) ;

$imageRow = mysql_query("SELECT * FROM store WHERE id=$id");

$image = mysql_fetch_assoc($imageRow);
$image = $image['image'];

header("Content-type: image/jpg");


echo $image;
  • 写回答

4条回答 默认 最新

  • duanchen7401 2011-05-18 18:12
    关注

    You can use different types of blobs. Blob, Mediumblob, longblob, etc.

    http://dev.mysql.com/doc/refman/5.0/en/blob.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效