Jump to content

Image resizing in PHP for mysql


emma57573

Recommended Posts

Im using a script that lets the user upload a file up to 400k.

But what I really want to do is resize the image before I save it. This is how I get the image:

 

if (is_uploaded_file($_FILES['userfile']['tmp_name'])) 
{
$realname = $_FILES['userfile']['name'];
///////--------chking extension	
if(!preg_match("/(\.jpg|\.png|\.gif|\.bmp|\.jpeg)$/i",$realname))
	die();
///////--------end chking extension	





if ($_FILES['userfile']['size']>(400000))
	$mess="Uploaded files must be less than ".(400000/1000)."k. Please try again";
elseif($_FILES['userfile']['size']<=0)
	$mess="File could not be uploaded. Please try again";
else
{
	$insert="no";
	switch($_FILES['userfile']['error'])
	{ case 0: $mess = "Image has been uploaded successfully"; $insert="yes";	  break;
	  case 1:
	  case 2: $mess = "Error : File size more than maximum size allowed by server";break;
	  case 3: $mess = "Error : File partially uploaded"; break;
	  case 4: $mess = "Error : No File Uploaded";
	  break;
	}
           

 

Obviously theres more to it but thas the important part now instead of finding out what size it is and throuwing up an error, I want to find out what size it is and if its over 250k I want to resize it down to 250k.

is there any simple bit of code that does it Ive looked at some scripts for this but cant find one that would let me do it simply without changing my entire code?

Link to comment
https://forums.phpfreaks.com/topic/129193-image-resizing-in-php-for-mysql/
Share on other sites

You should read this: http://nl2.php.net/manual/en/function.imagesx.php

 

That lets you get the image width as an integer...once you have that, you can just check it with an if statement...

 

Oh, does require the GD Library to be available...you can check that with

<?php
phpinfo();
?>

 

Then look for the GD part and see if it's enabled...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.