I am trying to get images from while loop and split them up at the period (.).. and then change the name of the image to ImageName + -resized. But I can not seem to figure out how to do this. Any help would be greatly appreciated!
So in short I have this: image.jpg and I want to create this image-resized.jpg: Here is my code:
<?php
$f = $_GET['f'];
$h = $_GET['h'];
$gp = $_GET['gp'];
//Create folder path
$path = "Fotos/".$f."/".$h."/".$gp."/";
//Get pictures from database
$getfolders = mysql_query("SELECT FolderName, Files FROM Files WHERE FolderDate = '$f' AND FolderHour = '$h' AND FolderName = '$gp'") or die(mysql_error());
//List pictures from database
while($row = mysql_fetch_array($getfolders)){
$img = $row['Files'];
//Seperate image at period(.)
$image = explode('.', $img);
//Get image name ----------------Here is where I need help!!
for($i = 0; $i < sizeof($image); $i++)
{
$imag = $image[$i];
}
?>
<div class="picture" id="pic"><img src="<?php echo $path; echo $imag ?>" alt="picture" /><?php echo $img?></div>
<?php
}
?>
Well, the simplest solution would be:
But this solution does assume, that there are only simple extensions:
But if there are only simple extensions, this solution might be sufficient.
A better solution would be using
SplFileInfo:SplFileInfo::getExtensions()is available since PHP 5.3.6