好,
所以我有一个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();
}
?>
这是一个简化版本。但是,当我单独运行调整大小代码时,代码可以正常工作。想法?
再次感谢!
答案 0 :(得分:1)
您错误地指定了'source'文件名。必须通过temp_name事物访问源文件。因此,代码中的这一行是错误的:
$image->image_to_resize = "./../users/$get_username/pictures/$new_id.jpg";
相反,这样做:
$image->image_to_resize = $_FILES['userfile']['tmp_name'];