# Uploading and Resizing Via Flash

**URL:** https://forum.kirupa.com/t/uploading-and-resizing-via-flash/298774
**Category:** programming
**Created:** [October 24, 2009, 8:12pm UTC](https://forum.kirupa.com/t/uploading-and-resizing-via-flash/298774 "2009-10-24T20:12:12Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pod\_clock](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@pod\_clock](https://forum.kirupa.com/u/pod_clock)
#### Post date: [October 24, 2009, 8:12pm UTC](https://forum.kirupa.com/t/uploading-and-resizing-via-flash/298774/1 "2009-10-24T20:12:12Z")

</div>

HI, I have a simple PHP script, which takes a file reference from Flash and then resizes and uploads the image. The script works fine until I add any conditional statement, so this works:

```php
<?php 

//max width
$maxw=500;

//target directory
$dir="../images/";

//save path
$target = $dir . basename( $_FILES['Filedata']['name']) ; 

//the uploaded file
$uploadedfile = $_FILES['Filedata']['tmp_name'];

//array image width and height
list($width,$height)=getimagesize($uploadedfile);

//test for width and height here
$newwidth=$maxw;
$newheight=($height/$width)*$newwidth;

//create a source image to manipulate 
//Returns an image resource identifier on success, FALSE on errors.
$src = imagecreatefromjpeg($uploadedfile);

//create a color image
//Returns an image resource identifier on success, FALSE on errors.
$tmp=imagecreatetruecolor($newwidth,$newheight);

//boolean
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);

//write the jpeg
if(imagejpeg($tmp,$target,100)) { 
	imagedestroy($src);
	imagedestroy($tmp);
	echo "The file has been uploaded"; 
} 

?>

```

But this doesn’t, where I’ve inserted an if statement to test for a landscape image:

```php
<?php 

//max width
$maxw=500;

//target directory
$dir="../images/";

//save path
$target = $dir . basename( $_FILES['Filedata']['name']) ; 

//the uploaded file
$uploadedfile = $_FILES['Filedata']['tmp_name'];

//array image width and height
list($width,$height)=getimagesize($uploadedfile);

//test for width and height here
$newwidth=$maxw;
$newheight=($height/$width)*$newwidth;

//any conditional prevents the upload from completing
if ($width > $height) {

}

//create a source image to manipulate 
//Returns an image resource identifier on success, FALSE on errors.
$src = imagecreatefromjpeg($uploadedfile);

//create a color image
//Returns an image resource identifier on success, FALSE on errors.
$tmp=imagecreatetruecolor($newwidth,$newheight);

//boolean
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);

//write the jpeg
if(imagejpeg($tmp,$target,100)) { 
	imagedestroy($src);
	imagedestroy($tmp);
	echo "The file has been uploaded"; 
} 

?>

```
