上传后调整图片大小,无法正常工作?
问题描述:
所以我有一个PHP文件,上传图像到我的服务器。上传后,我想将图像大小调整为100X100文件。下面是我的代码不起作用。
请帮忙!
<?php
include 'resize.image.class.php';
$get_username = "usernamehere";
$new_id = "19";
$uploadDir = "./../users/$get_username/pictures/";
$file = basename($_FILES['userfile']['name']);
$uploadFile = $file;
$newName = $uploadDir . $new_id . $uploadFile;
$file_size = $_FILES['userfile']['size'];
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$image = new Resize_Image;
$image->new_width = 100;
$image->new_height = 100;
$image->image_to_resize = "./../users/$get_username/pictures/$new_id.jpg"; // Full Path to the file
$image->ratio = true;
$image->new_image_name = "$new_id";
$image->save_folder = "./../users/$get_username/pictures/thumbnails/";
$process = $image->resize();
}
?>
这是一个简化版本。但是,当我单独运行调整大小的代码时,代码工作。思考?
再次感谢!
答
您错误地指定了'源'文件名。源文件必须由temp_name事物访问。所以,这行代码中的故障:
$image->image_to_resize = "./../users/$get_username/pictures/$new_id.jpg";
相反,这样做:
$image->image_to_resize = $_FILES['userfile']['tmp_name'];
有什么错误?什么是resize.image.class.php? – Jacob 2011-02-17 05:55:00
唯一的错误:该文件不存在。 – iosfreak 2011-02-17 05:56:22