I have a screip to resize an image, save it to a dir and store the path in mysql. This works ok. The images are gotten from a suppliers website where the filename of each is the product code.
The variable $remote_file in my code looks like this ../images/products/wsx339.jpg. How would i just get the filename minus the jpg bit so i can put it in my 'code' field in mysql? At the minute I have to manually input it into a form.

Heres the code.

$remote_file = "../images/products/".$_FILES["image_upload_box"]["name"];
      imagejpeg($image_source,$remote_file,100);
      chmod($remote_file,0644);

      imagejpeg($image_source,$remote_file,100);
      chmod($remote_file,0644);


               $thumb_height = 450;
               $thumb_width = 450;
               list($image_width, $image_height) = getimagesize($remote_file);
               if($image_width>$thumb_width || $image_height >$thumb_height){
                  $proportions = $image_width/$image_height;
                  $new_height = $thumb_height;
                  $new_width = round($thumb_height*$proportions);
                  $thumb_image = imagecreatetruecolor($new_width , $new_height);
                  $image_source = imagecreatefromjpeg($remote_file);
                  imagecopyresampled($thumb_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
                  imagejpeg($thumb_image,$remote_file,100);
                  imagedestroy($thumb_image);
                  //add the files pathname to the database table products
                  $cat1 = intval($_POST['cat']);
                  $cat2 = intval($_POST['subcat']);
                  $aname = $_POST['aname'];
                  $aprice= $_POST['aprice'];
                  $acode= $_POST['acode'];
                  $adescription = $_POST['adescription'];
                  $description = mysqli_real_escape_string($link, $adescription);
                  $name = mysqli_real_escape_string($link, $aname);
                  $code = mysqli_real_escape_string($link, $acode);
                 $query = "INSERT INTO products VALUES('NULL', '$name', '$description', '$aprice', '$remote_file', '$cat1', '$cat2', '$code', 1)";
                 $result = $link->query($query);
                 if(!$result){
                    echo 'Something went wrong';
                 }   
                 header( 'Location: ../admin/productsadd.php' ) ;
     }
}
Member Avatar for iamthwee

Why would you need to take out the file extension?

Because the product code is just the wsx339 bit. I want to put that into my tables 'code' field.

Found it.

$acode = $_FILES["image_upload_box"]["name"];
$code = pathinfo($acode, PATHINFO_FILENAME);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.