Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Almost done with this thumbnail script
Old 02-16-2008, 09:10 PM Almost done with this thumbnail script
Average Talker

Posts: 27
Location: CT
Trades: 0
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>'; 
	} 
}

 ?>
DBookatay is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-16-2008, 09:26 PM Re: Almost done with this thumbnail script
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
if you want the file extension to be lower case then do the following:
PHP Code:
$file_ext strtolower($file_ext); 
Hope that helps. By the way using the PHP tag rather than the CODE tag makes it easier to read your php, also some of your lines are extremely long. Breaking them up into smaller lines improves readibility.
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-18-2008, 02:15 AM Re: Almost done with this thumbnail script
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
And please learn to use imagemagick's convert and mogrify command line utilities to resize pictures. If somebody uploads a dozen of hi-res pictures simultaneously your script would simply crash due to memory limits. And if you then try to fix the problem by increasing php memory_limit value you can easily get your server hung.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 02-20-2008, 12:56 AM Re: Almost done with this thumbnail script
Average Talker

Posts: 27
Location: CT
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
And please learn to use imagemagick's convert and mogrify command line utilities to resize pictures. If somebody uploads a dozen of hi-res pictures simultaneously your script would simply crash due to memory limits. And if you then try to fix the problem by increasing php memory_limit value you can easily get your server hung.
The only one that would EVER use this script would be the site admin... Which is me, so I dont need to worry about that.
DBookatay is offline
Reply With Quote
View Public Profile
 
Old 02-20-2008, 02:04 AM Re: Almost done with this thumbnail script
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Well, once you will try to create a script for users to upload images.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Almost done with this thumbnail script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15107 seconds with 12 queries