Php Joomla 2.5 Alphauserpoints可选图像大小调整器

Php Joomla 2.5 Alphauserpoints可选图像大小调整器,php,image,joomla,resize,Php,Image,Joomla,Resize,无法实现图像大小调整器脚本: <?php // Create image from file switch(strtolower($_FILES['Filedata']['type'])) { case 'image/jpeg': $image = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']); break; case 'image/png': $image = imagecr

无法实现图像大小调整器脚本:

<?php
// Create image from file
switch(strtolower($_FILES['Filedata']['type']))
{
case 'image/jpeg':
         $image = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']);
         break;
case 'image/png':
         $image = imagecreatefrompng($_FILES['Filedata']['tmp_name']);
         break;
case 'image/gif':
         $image = imagecreatefromgif($_FILES['Filedata']['tmp_name']);
         break;
}
// Target dimensions
$max_width = 240;
$max_height = 180;
// Get current dimensions
$old_width = imagesx($image);
$old_height = imagesy($image);
// Calculate the scaling we need to do to fit the image inside our frame
$scale   = min($max_width/$old_width, $max_height/$old_height);
// Get the new dimensions
$new_width = ceil($scale*$old_width);
$new_height = ceil($scale*$old_height);
// Create new empty image
$new = imagecreatetruecolor($new_width, $new_height);
// Resize old image into new
imagecopyresampled($new, $image,
0, 0, 0, 0,
$new_width, $new_height, $old_width, $old_height);

// Catch the imagedata
ob_start();
imagejpeg($new, NULL, 90);
$data = ob_get_clean();
// Destroy resources
imagedestroy($image);
imagedestroy($new);
?>
无法获取与此相同的数据:

$_FILES['Filedata']
这就是我可能有问题的原因。 但是转换脚本本身会独立工作,获取图像数据,调整图像大小并返回图像,问题是用当前脚本实现它

如果我真的替换了这个:

$file = $_FILES['Filedata']
为此:

$file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
它会检索相同的图像数据吗

我通常能做很多这类的事情,虽然这需要我一段时间,但这件事让我陷入困境。 我还没有达到我能知道如何使它工作的水平,我必须通过反复试验和研究,通过实例来做到这一点,这很困难

我试着把下面的内容放在“检查是否有伪造”的评论下面,然后去掉$file=。。。。然后将$file字符串的其余部分更改为$newfile,但运气不好,它要么返回错误,要么忽略调整大小脚本,这取决于我是否删除$file=。。。等等

// Target dimensions
$max_width = 240;
$max_height = 180;
// Get current dimensions
$old_width = imagesx($file);
$old_height = imagesy($file);
// Calculate the scaling we need to do to fit the image inside our frame
$scale   = min($max_width/$old_width, $max_height/$old_height);
// Get the new dimensions
$new_width = ceil($scale*$old_width);
$new_height = ceil($scale*$old_height);
// Create new empty image
$new = imagecreatetruecolor($new_width, $new_height);
// Resize old image into new
imagecopyresampled($new, file,
0, 0, 0, 0,
$new_width, $new_height, $old_width, $old_height);
// Catch the imagedata
ob_start();
imagejpeg($new, NULL, 90);
$filenew = ob_get_clean();
// Destroy resources
imagedestroy($file);
imagedestroy($new);
$file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
// Target dimensions
$max_width = 240;
$max_height = 180;
// Get current dimensions
$old_width = imagesx($file);
$old_height = imagesy($file);
// Calculate the scaling we need to do to fit the image inside our frame
$scale   = min($max_width/$old_width, $max_height/$old_height);
// Get the new dimensions
$new_width = ceil($scale*$old_width);
$new_height = ceil($scale*$old_height);
// Create new empty image
$new = imagecreatetruecolor($new_width, $new_height);
// Resize old image into new
imagecopyresampled($new, file,
0, 0, 0, 0,
$new_width, $new_height, $old_width, $old_height);
// Catch the imagedata
ob_start();
imagejpeg($new, NULL, 90);
$filenew = ob_get_clean();
// Destroy resources
imagedestroy($file);
imagedestroy($new);