我有一个效果很好的图片上传表单。它上传到一个文件夹,但我希望它为上传的文件提供特定的高度和宽度,以便它适合页面。有人可以帮我吗?
谢谢!
<?php
$uploadpath = 'upload/';
$max_size = 2000;
$alwidth = 250;
$alheight = 400;
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png');
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
$err = '';
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/> Maximale waarden: '. $alwidth. ' x '. $alheight . '  probeer opnieuw';
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo "Uw afbeelding is succesvol opgeslagen";
}
else echo '<b>Unable to upload the file.</b>';
}
else echo $err;
}
?>
<div style="width:500px;;margin:1em auto; width:333px; text-align:center;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="file" name="fileup" /><br/>
<input type="submit" name='submit' value="Upload" />
</form>
</div>
</div>
</div></div>
</div>
</body>
</html>