2014-05-02 82 views
0

我上傳的圖像到服務器使用php.And我也生成一個隨機圖像編號後id.Now上傳圖像的名稱,如6_1.jpg,5_4.jpg等,其中第一個數字是id(之前_)和其他是隨機生成的數字(_之後)。我的代碼如下從服務器獲取圖像

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; 

} 

現在,我怎麼顯示從服務器到我家page.Please幫助me.Thanks圖片提前

+0

直接添加URL或保存數據庫並上傳目錄,然後使用路徑 –

+0

,可以儲存'$數據[「IMG」]'在DB – MrRP

+0

@RakeshSharma我要動態地顯示圖像.. –

回答

0

用頭功能

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

每個圖片。