簡體   English   中英

class.upload.php和文件擴展名丟失

[英]class.upload.php and file extension missing

我正在使用class.upload.php獲取圖像。 調整大小可以正確使用名稱和擴展名進入文件夾,但是將名稱存儲到mysql數據庫時出現問題。 沒有文件擴展名(.jpg,.gif等)...為什么? 我該如何解決該問題? 謝謝

     /* ========== SCRIPT UPLOAD MULTI IMAGES  ========== */
     include('class.upload.php');
      $dir_dest="../../images/gallery/";  

    $files = array();
  foreach ($_FILES['fleImage'] as $k => $l) {
    foreach ($l as $i => $v) {
        if (!array_key_exists($i, $files))
            $files[$i] = array();
        $files[$i][$k] = $v;
    }
}

foreach ($files as $file) {

    $handle = new Upload($file);
      if ($handle->uploaded) {

    $mainame = $handle->file_dst_name;

    $db_name = str_replace(" ","_",$mainame);
    $image1 = md5(rand() * time()) . ".$db_name";
    $parts = explode(".",$image1);
    $extension = end($parts);
    $result_big = str_replace("." . $extension,"",$image1);

         $handle->file_new_name_body   =  $result_big;
         $handle->image_resize     = true;
         $handle->image_x          = 460;
         $handle->image_ratio_y    = true;
        // $handle->image_y          = 400;
         $handle->Process($dir_dest);

        //Thumbnail
     $db_name = str_replace(" ","_",$mainame);
     $image1 = md5(rand() * time()) . ".$db_name";
     $parts = explode(".",$image1);
     $extension = end($parts);
     $result_small = str_replace("." . $extension,"",$image1);    

         $handle->file_new_name_body   =    $result_small;
         $handle->image_resize     = true;
         $handle->image_x          = 180;
         $handle->image_ratio_y = true;
        // $handle->image_y          = 120;
         $handle->Process($dir_dest);

         // we check if everything went OK
        if ($handle->processed) {
              header("Location: index.php");    //echo 'image resized';
               $handle->clean();

    $query_img="INSERT into tbl_images (file_name, pd_image, pd_thumbnail) VALUES('$nome','$result_big', '$result_small')";      
       $result2 = dbQuery($query_img);

  } else {
      echo 'error : ' . $handle->error;
  }
    }
     }
// END SCRIPT UPLOAD MULTI IMAGES

 header("Location: index.php"); 
}

您已經在這里使用str_replace用空字符串替換了擴展

$result_small = str_replace("." . $extension,"",$image1);

和這里

$result_big = str_replace("." . $extension,"",$image1);

更新以下幾行只需在末尾添加.$extension

$handle->file_new_name_body   =  $result_big.$extension;

 $handle->file_new_name_body   =    $result_small.$extension;

只是像這樣更改查詢

$query_img="INSERT into tbl_images ( 
                file_name, 
                pd_image, 
                pd_thumbnail
             ) VALUES (
               '$nome',
               '{$result_big}.{$extension}', 
               '{$result_small}.{$extension}')";   

我建議您為pd_imagepd_thumbnail使用相同的文件名,只是在thumb之前加上thumb_ ,這樣可以使您的生活更加輕松。

這樣你可以用前綴它訪問任何圖像縮略圖thumb_pd_image ,你不必存儲pd_thumbnail數據庫。

您正在使用以下代碼刪除擴展名:$ result_big = str_replace(“。”。$ extension,“”,$ image1);

我不知道你為什么這樣做。 無論如何,您可以通過在$ handle-> file_new_name_body = $ result_big之后添加以下行來將其重新添加回去。

$ handle-> file_new_name_ext = $ extension;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM