我希望在网络verot class.upload.php上找到的上传文件大小 但不幸的是,它不能与我合作,没有上传,没有调整大小,.. 所以我的问题是这个API需要某种安装, 因为我只将class.upload.php上传到我的服务器 我的功能就是那个
public function myImageR()
{
$foo = new Upload($_FILES['img']);
if ($foo->uploaded) {
// save uploaded image with no changes
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
} else {
$a = false;
}
// save uploaded image with a new name
$foo->file_new_name_body = 'foo';
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
} else {
$a = false;
}
// save uploaded image with a new name,
// resized to 100px wide
$foo->file_new_name_body = 'image_resized';
$foo->image_resize = true;
$foo->image_convert = gif;
$foo->image_x = 100;
$foo->image_ratio_y = true;
$foo->Process('/public/images/aa/');
if ($foo->processed) {
$a = true;
$foo->Clean();
} else {
$a = false;
}
}
}
但它根本不起作用我在使用xammp的localhost工作
答案 0 :(得分:2)
您需要安装GD lib ...如果您使用的是ubuntu示例:
sudo apt-get install php5-gd
然后重启Apache
sudo /etc/init.d/apache2 restart
无论如何,我用它来调整我使用它的图像:
上传:
$uploaded_filename = '/www/html/picts/yourfoto.jpg';
if(isset($_FILES['your_files_field_name'])){
if (move_uploaded_file($_FILES['your_files_field_name']['tmp_name'], $uploaded_filename)) {
chmod($uploaded_filename, 0755);
return $nome; // OK
} else {
return "ERROR";
}
}
要调整大小:
<?php
$w = 40; // set width
$h = 40; // set height
$path = './'; // path
$image_file = (string) filter_input(INPUT_GET, 'img');
$image_path = $path . $image_file;
$img = null;
$ext = @strtolower(end(explode('.', $image_path)));
if ($ext == 'jpeg') {
$img = imagecreatefromjpeg($image_path);
} else if ($ext == 'jpg') {
$img = imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = imagecreatefrompng($image_path);
} elseif ($ext == 'gif') {
$img = imagecreatefromgif($image_path);
} elseif ($ext == 'bmp') {
$img = imagecreatefromwbmp($image_path);
} else {
exit("File type not found: " . $ext);
}
if ($img) {
$width = imagesx($img);
$height = imagesy($img);
$scale = min($w / $width, $h / $height);
if ($scale < 1) {
$new_width = floor($scale * $width);
$new_height = floor($scale * $height);
$tmp_img = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
if (!$img) {
$img = imagecreate($w, $h);
imagecolorallocate($img, 204, 204, 204);
$c = imagecolorallocate($img, 153, 153, 153);
$c1 = imagecolorallocate($img, 0, 0, 0);
imageline($img, 0, 0, $w, $h, $c);
imageline($img, $w, 0, 0, $h, $c);
imagestring($img, 2, 12, 55, 'IMAGE ERROR', $c1);
}
header('Content-type: ' . 'image/png');
imagejpeg($img);
如果要将已调整大小的文件保存在磁盘中:
$file = '/www/html/picts/yourfoto.jpg';
$save = imagejpeg($img, $file); // save the file
我希望这有帮助!