Re: FUNCTION TO CHECK IMAGE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



BBC wrote:
What types of images are these? JPG, PNG, GIF?
Its jpg. Look... I don't know exactly what your point, I'm just asking you about the function to resolve the size of image like the
codes below:
if (file_exists($img_path)){
list($width,$height) = getimagesizes($img_path);
}else{
$width = $ height = $max_size;
}
So is there any other option to replace file_exists();?


Well, if I do remember correctly, then you are uploading a file. If that's the case, then rather than using file_exists() you should be using is_uploaded_file. Once you've verified that is_uploaded_file() returns true, then use move_uploaded_file() to move the file to someplace on your filesystem. If that returns true, then you should not have to check file_exists again and just be able to use get getimagesize().

So, a good function for this would probably be:

function getUploadedImageSize($image, $to_path) {
	global $max_size;

	$width = $height = $max_size;

	if (is_uploaded_file($image)) {
		if (move_uploaded_file($image, $to_path)) {
			list($width,$height) = getimagesize($to_path);
		}
	}

	return array($width, $height);
}

list($width, $height) = getUploadedImageSize($tmp, '/the/final/path');

BTW, I don't know if you did a copy and paste from your code or if you just typed it in really quickly, but you do have a few syntactical errors in the code above. First, the image sizing function is getimagesize - singular, not plural. Second, in your assignment statement, you have a space where there should not be one:

$width = $ height = $max_size;
         ^

Just wanted to make sure you knew about that in case it was copied and
pasted.

thank you for your input, it really helps.
========================================================================================
Semarakkan kemerdekaan RI ke 61 th dengan ikut bermain netkuis 17-an di http://netkuis.telkom.net/17an/
Kumpulkan poin sebanyak-banyaknya. Dan siap-siap tunggu rejeki dari sponsor kami.

========================================================================================
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux