Can anyone show me where to add the strtolower(____HERE____) to my code below?
This is a image upload / thumbnail script that I found, and made a few additions to.
Problem is I want the files to be renamed on my server, and in the dB all lowercase.
No matter what I try, it still comes back like: 120_4353.JPG
Code:
<?
} else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') {
// Set $url To Equal The Filename For Later Use
$url = $_FILES['imagefile']['name'];
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") {
// Get The File Extention (.jpg, .gif or .php)
$file_ext = strrchr($_FILES['imagefile']['name'], '.');
// Move Image From Temporary Location To Permanent Location
$copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . strtolower($_FILES['imagefile']['name']));
// If The Script Was Able To Copy The Image To It's Permanent Location
if ($copy) {
// Successfull Upload
$url = strtolower($url);
$simg = imagecreatefromjpeg("$idir" . $url);
// Make A New Temporary Image To Create The Thumbnail From
// Current Image Width
$currwidth = imagesx($simg);
// Current Image Height
$currheight = imagesy($simg);
// If Height Is Greater Than Width
if ($currheight > $currwidth) {
// Length Ratio For Width
$zoom = $twidth / $currheight;
// Height Is Equal To Max Height
$newheight = $theight;
// Creates The New Width
$newwidth = $currwidth * $zoom;
} else {
// Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
// Length Ratio For Height
$zoom = $twidth / $currwidth;
// Width Is Equal To Max Width
$newwidth = $twidth;
// Creates The New Height
$newheight = $currheight * $zoom;
}
// Make New Image For Thumbnail
$dimg = imagecreate($newwidth, $newheight);
// Create New Color Pallete
imagetruecolortopalette($simg, false, 256);
$palsize = ImageColorsTotal($simg);
// Counting Colors In The Image
for ($i = 0; $i < $palsize; $i++) {
// Number Of Colors Used
$colors = ImageColorsForIndex($simg, $i);
// Tell The Server What Colors This Image Will Use
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']);
}
// Copy Resized Image To The New Image (So We Can Save It)
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
// Saving The Image
imagejpeg($dimg, "$tdir" . $url);
imagedestroy($simg); // Destroying The Temporary Image
imagedestroy($dimg); // Destroying The Other Temporary Image
// Resize successful
echo '<table><tr><td><img src="http://www.carcityofdanbury.com/inventory/'.$idir.strtolower($url).'" width="365" height="274" /></td></tr><tr><td class="upTxt"><img src="../images/Common/Icons/bulletOn.gif"> Image successfully added.</td></tr><tr><td class="upTxt"><img src="../images/Common/Icons/bulletOn.gif"> Thumbnail successfully created.</td></tr></table><div class="close"><a href="javascript:parent.window.focus(); top.window.close();" onclick="window.opener.location.href = \'http://www.login.carcityofdanbury.com/passed/edit.php?category=001&stock='.$stock.'\'">Close Window</a></div>';
if ($copy) {$mysql_query = "UPDATE Inventory SET $field = '$url' WHERE stock= '$stock'"; mysql_query($mysql_query) or die(mysql_error());}
} else {
// If Upload Failed
echo '<font color="#FF0000">ERROR: Unable to upload image.</font>';
}
} else {
// Not .jpg or .JPG file
echo '<font color="#FF0000">ERROR: Wrong filetype (has to be a .jpg or .jpeg. Yours is ';
echo $file_ext; // Show The Invalid File's Extention
echo '.</font>';
}
}
?>
|