0

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

Edited by GlenRogers

2
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by GlenRogers
0

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

0

Found it.

$acode = $_FILES["image_upload_box"]["name"];
$code = pathinfo($acode, PATHINFO_FILENAME);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.