Ogum
Ogum

Reputation: 379

Uploading image into mysql DB with class.upload.php. No extension for the image name

I'm trying to use the class.upload.php. it works, but when i store into the mysql database the image name, i don't have the extension of the file (.jpg). Into the folder the image name is uploaded with the extension.

Example. Into the folder i have the image name dedafab546ea17dd3093c782a7193e99.jpg...ok

into the DB i have dedafab546ea17dd3093c782a7193e99....no extension.

i didn't understand why.... Any suggestion? Thanks!!

$name        = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$meta_desc = $_POST['metaDescription'];
$parentId    = $_POST['hidParentId'];
$name_img        = $_FILES['fleImage']['name'];


include('class.upload.php');
$dir_dest="../../images/category/";  


$handle = new Upload($_FILES['fleImage']); 
  if ($handle->uploaded) {

    $mainame = $handle->file_dst_name;    
    $db_name = str_replace(" ","_",$mainame);
    $image = md5(rand() * time()) . ".$db_name";
    $parts = explode(".",$image);
    $extension = end($parts);
    $result_big = str_replace("." . $extension,"",$image);                                   

         $handle->file_new_name_body   =  $result_big;
         $handle->image_resize     = true;
         $handle->image_convert = jpg;
         $handle->image_x          = 358;
         $handle->image_ratio_crop   = true;
         $handle->image_y          = 180;
         $handle->Process($dir_dest);

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


$sql   = "INSERT INTO tbl_category (cat_parent_id, cat_name, cat_description, cat_image, meta_desc) 
          VALUES ($parentId, '$name', '$description', '$result_big', '$meta_desc')";
$result = dbQuery($sql) or die('Cannot add category' . mysql_error());

header('Location: index.php?catId=' . $parentId);  

  } else {
      echo 'error : ' . $handle->error;
  }
    }
     }

Upvotes: 0

Views: 96

Answers (1)

user128161
user128161

Reputation:

The following line is replacing the extension with nothing

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

Upvotes: 1

Related Questions