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"); 
}

您正在使用以下代码删除扩展$result_big=str_replace(".".$extension,",$image1);

我不知道你为什么那样做。无论如何,您可以通过在$handle->file_new_name_body=$result_big;

$handle->file_new_name_ext=$extension;

您已经使用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存储在数据库中。