Why does my file not resize?

I am trying to upload and resize a file. Can you tell me why my file does not resize. It uploads fine but the resize does not work.
if (isset($_FILES['image'])) {
echo "hello";
mkdir("../../property_images/$property_id/", 0700);
list($width, $height, $type, $w) = getimagesize($_FILES['userfile']['tmp_name']);
$imageinfo = getimagesize($_FILES['userfile']['tmp_name']);
echo $width=$imageinfo[0];
echo $height=$imageinfo[1];
$newwidth = 300;
$newheight = 200;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['image']['tmp_name']);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, 400, 300, $width, $height);
	$ftmp = $_FILES['image']['tmp_name'];
	$oname = $_FILES['image']['name'];
	$fname = "../../property_images/$property_id/".$_FILES['image']['name'];
	if(move_uploaded_file($ftmp, $fname)){
// do something

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You probably need to do a imagejpeg($thumb, 'path/to/your/new/thumb.jpg') in order for a thumbnail file to be stored.

It might also be that for the $source image, you need to use the image ?fter you moved it using move_uploaded_file, rather than before.

What warning or message do you get at this stage that tells you that thumbnailing fails?

Kind regards

in line 7 you should use douple quates if you are to put vriables inside string
also, try this function to resize jpg pics, through to it image source ($_FILES['image']['tmp_name']) , where to save the new created image, desired width and height can be either automatically calculated keeping aspect ratio or you can specify it
function resizePic ($src,$target,$width,$height=0){
	$allowedPics = array('.jpg','jpeg');
	$ext = strtolower(substr($src,strrpos($src,'.')));
	if (in_array($ext,$allowedPics)){
		$srcImage = ImageCreateFromJPEG ($src);
		$orginalW = imagesx($srcImage);
		$orginalH = imagesy($srcImage);
		$ratio = $orginalW/$orginalH;
		$quality = 60;
		$height = (!$height) ? $width/$ratio : $height;
		$image  = ImageCreateTrueColor($width,$height);
	} else {
		die ("unsupported image");
resizePic($_FILES['image']['tmp_name'] ,$_FILES['image']['name'],300);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.