doujia9833 2014-05-02 11:41
浏览 67

从服务器获取图像

I uploaded image to the server using php.And i also generate a random image number after the id.Now the name of the uploaded image like 6_1.jpg, 5_4.jpg etc, Where 1st number is the id (before _) and other is randomly generated number(after _). My codes are as below

function upload_receipt_img(){
    $random_digit = rand(0,9);          
    $receipt_id = $_POST['id'];      
        if (isset($_POST['data_url'])) {      
            $file = $receipt_id._.$random_digit.'.jpg';
            $img = substr($_POST['data_url'], strpos($_POST['data_url'], ",") + 1);
            $decodedData = base64_decode($img);
            $success = file_put_contents('assets/receipt_img/' . $file, $decodedData);
            //resize main image
            $source_path = "assets/receipt_img/" . $file;
            $destination = "assets/receipt_img/" . $file;
            $newwidth = 350;
            $this->resizeImg($newwidth, $source_path, $destination);
            $data['img'] = 'assets/receipt_img/' . $receipt_id.$random_digit.'.jpg';
        }
    $this->closeConnection();
    echo $receipt_id;

}

Now how can i show images from the server to my home page.Please help me.Thanks in advance

  • 写回答

1条回答 默认 最新

  • dongyun51582 2014-05-02 12:31
    关注

    Use header function as

    <?php 
      header('Content-type: image/jpeg'); 
      readfile($destination); // image file path
    ?>
    

    for each image.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程